Hello! I am new with pytorch and fastai.
Does anybody know how to add some custom pretrained models to my fastai 1.0.28 code?
These for example: https://github.com/Cadene/pretrained-models.pytorch
Answered here --> https://forums.fast.ai/t/lesson-5-advanced-discussion/30865/7?u=shar1
Great thanks!
But it doesn’t work and fails with error:
TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not bool
Could you make it run yet? Would be interesting to know.
Try this:
def get_model(pretrained=False, **kwargs):
model = se_resnet50(**kwargs) #pass parameters here. se_resnet50 as an example
return model
Create one function get_model, which returns the model. Pass get_model in create_cnn.
It did not work for me. I am on fastai v1.39
Here is my minimal code that I tried on the standard resnet50 before trying more fancy cadene models.
How did you do it with se_resnet
? Did you use cadene library?
Update: I could make create_cnn
work with custom model. Here is my code:
https://forums.fast.ai/t/lesson-5-advanced-discussion/30865/40?u=hwasiti
Hello, all!
I have 1.0.30 version and what I do:
import pretrainedmodels
def model_f(pretrained=True, **kwargs):
return pretrainedmodels.se_resnext50_32x4d(num_classes=1000,
pretrained='imagenet')
learn = fastai.vision.learner.create_cnn(
data = data,
arch=model_f,
cut=-2) #cut parameter is different for each model
Hope, it will help!
[ EDIT ] : this issue is solved (see thread [ SOLVED ] Get prediction from the ImageNet model without creating a databunch).
Hello @myltykritik.
I’m searching an answer in the forum about how to use a pretrained model without changing anything. For example, I would like to use resnet34 with the 1000 classes of ImageNet.
It is easy to get the weights (for example, model = models.resnet34(pretrained=True)
), but how to use it after to get a prediction through model.predict(img)
? I got the following error.
AttributeError: 'ResNet' object has no attribute 'predict'
I guess I need to build a learner with create_cnn(data, model)
for example but for that I need a databunch data
with my 1000 classes… and I do not want to download the 138 GB of Imagenet training dataset Any advice?