Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17331

PyTorch get all layers of model

$
0
0

What's the easiest way to take a pytorch model and get a list of all the layers without any nn.Sequence groupings? For example, a better way to do this?

import pretrainedmodelsdef unwrap_model(model):    for i in children(model):        if isinstance(i, nn.Sequential): unwrap_model(i)        else: l.append(i)model = pretrainedmodels.__dict__['xception'](num_classes=1000, pretrained='imagenet')l = []unwrap_model(model)            print(l)

Viewing all articles
Browse latest Browse all 17331

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>