I use https://github.com/Cadene/pretrained-models.pytorch, and
all the model works well if I don’t use fastai.
When I use fastai, if the network has 2 parameters in forward(), create_cnn gives errors.
like line 284 in https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/models/pnasnet.py
for example :
def pnasnet5large(pretrained=True):
model = pretrainedmodels.pnasnet5large(num_classes=1000, pretrained=‘imagenet’)
model.conv_0 = nn.Sequential(OrderedDict([
(‘conv’, nn.Conv2d(4, 96, kernel_size=3, stride=2, bias=False)),
(‘bn’, nn.BatchNorm2d(96, eps=0.001))
]))
model.last_linear = nn.Linear(4320, 28)
model.avg_pool = nn.AdaptiveAvgPool2d(1)
return model
learn = create_cnn(
data,
pnasnet5large,
ps=0.5,
cut=-3,
path=path,
metrics=[acc],
callback_fns=[ShowGraph]
)
learn.model = nn.DataParallel(learn.model)
it gives :
~/anaconda36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
–> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
~/anaconda36/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
90 def forward(self, input):
91 for module in self._modules.values():
—> 92 input = module(input)
93 return input
94
~/anaconda36/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
–> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
TypeError: forward() missing 1 required positional argument: ‘x_right’
Another one is :
def senet154(pretrained=True):
model_name = ‘senet154’
model = pretrainedmodels. dict [model_name](num_classes=1000, pretrained=‘imagenet’)
w = model.layer0.conv1.weight
model.layer0.conv1 = nn.Conv2d(4, 64, 3, stride=2, padding=1, bias=False)
model.layer0.conv1.weight = torch.nn.Parameter(torch.cat((w, w[:, 2, :, :].unsqueeze(1)), dim=1))
model.last_linear = nn.Linear(512 * 4, 28)
model.avg_pool = nn.AdaptiveAvgPool2d(1)
return model
learn = create_cnn(
data,
senet154,
ps=0.5,
cut=-3,
path=path,
metrics=[acc],
callback_fns=[ShowGraph]
)
learn.model = nn.DataParallel(learn.model)
It can work.
fastai:‘1.0.22’
pytorch:‘1.0’