简体   繁体   中英

Load pretrained pytorch model

Haven't been able to find this solution elsewhere though the question may seem really simple.

I have a pytorch (.pt) file and I'm trying to load it. I know that I need to construct the model first by doing

model = MyModel()

but my pytorch file buiilds a model (se_resnext101_32x4d) that I did not make a class for. As such when I try and do

model = se_resnext101_32x4d()

I get an error

name 'se_resnext101_32x4d' is not defined

I've tried doing

import pretrainedmodels

model = pretrainedmodels.__dict__[se_resnext101_32x4d]()

but the error persists.

After a little search, it appears you are trying to use this package which contains pretrained models and an API to download and use them. According to their documentation you can load a model like so:

import pretrainedmodels

Model = pretrainedmodels.__dict__['se_resnext101_32x4d']
model = Model(num_classes=1000, pretrained='imagenet')
model.eval()

Don't forget to install the pip package if you haven't already:

pip install pretrainedmodels

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM