lessw2020 / res2net-plus

Res2Net architecture with improved stem and Mish activation function
Apache License 2.0
136 stars 33 forks source link

TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not bool #1

Closed rbunn80110 closed 5 years ago

rbunn80110 commented 5 years ago

TypeError Traceback (most recent call last)

in 20 # true_wd=True, 21 # loss_func=LabelSmoothingCrossEntropy(), ---> 22 opt_func=optar, ps=0.001) ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/vision/learner.py in cnn_learner(data, base_arch, cut, pretrained, lin_ftrs, ps, custom_head, split_on, bn_final, init, concat_pool, **kwargs) 96 meta = cnn_config(base_arch) 97 model = create_cnn_model(base_arch, data.c, cut, pretrained, lin_ftrs, ps=ps, custom_head=custom_head, ---> 98 bn_final=bn_final, concat_pool=concat_pool) 99 learn = Learner(data, model, **kwargs) 100 learn.split(split_on or meta['split']) ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/vision/learner.py in create_cnn_model(base_arch, nc, cut, pretrained, lin_ftrs, ps, custom_head, bn_final, concat_pool) 82 bn_final:bool=False, concat_pool:bool=True): 83 "Create custom convnet architecture" ---> 84 body = create_body(base_arch, pretrained, cut) 85 if custom_head is None: 86 nf = num_features_model(nn.Sequential(*body.children())) * (2 if concat_pool else 1) ~/anaconda3/envs/fastai/lib/python3.7/site-packages/fastai/vision/learner.py in create_body(arch, pretrained, cut) 54 def create_body(arch:Callable, pretrained:bool=True, cut:Optional[Union[int, Callable]]=None): 55 "Cut off the body of a typically pretrained `model` at `cut` (int) or cut the model as specified by `cut(model)` (function)." ---> 56 model = arch(pretrained) 57 cut = ifnone(cut, cnn_config(arch)['cut']) 58 if cut is None: ~/anaconda3/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs) 545 result = self._slow_forward(*input, **kwargs) 546 else: --> 547 result = self.forward(*input, **kwargs) 548 for hook in self._forward_hooks.values(): 549 hook_result = hook(self, input, result) ~/PycharmProjects/baiby_prod/model_creation_notebooks/res2fg.py in forward(self, x) 281 282 #stem layers --> 283 x = self.conv1(x) 284 x = self.conv2(x) 285 x = self.conv3(x) ~/anaconda3/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs) 545 result = self._slow_forward(*input, **kwargs) 546 else: --> 547 result = self.forward(*input, **kwargs) 548 for hook in self._forward_hooks.values(): 549 hook_result = hook(self, input, result) ~/anaconda3/envs/fastai/lib/python3.7/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 ~/anaconda3/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs) 545 result = self._slow_forward(*input, **kwargs) 546 else: --> 547 result = self.forward(*input, **kwargs) 548 for hook in self._forward_hooks.values(): 549 hook_result = hook(self, input, result) ~/anaconda3/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/conv.py in forward(self, input) 341 342 def forward(self, input): --> 343 return self.conv2d_forward(input, self.weight) 344 345 class Conv3d(_ConvNd): ~/anaconda3/envs/fastai/lib/python3.7/site-packages/torch/nn/modules/conv.py in conv2d_forward(self, input, weight) 338 _pair(0), self.dilation, self.groups) 339 return F.conv2d(input, weight, self.bias, self.stride, --> 340 self.padding, self.dilation, self.groups) 341 342 def forward(self, input):
lessw2020 commented 5 years ago

Hi - you're going to have to provide more context than this :) Can you show how you are creating the network, etc? Or just share out your notebook?

rbunn80110 commented 5 years ago

This works when I use the built in models:

learn = cnn_learner(data, models.resnet152,

res2net(num_classes=2, depth=152),

                metrics=[accuracy, dice, Precision(average='macro'),Recall(average='macro'),FBeta(average='macro')], 
                callback_fns=[ShowGraph],
                wd=1e-3,
                bn_wd=False,
                true_wd=True,
                loss_func=LabelSmoothingCrossEntropy(),
                opt_func=optar, ps=0.001).to_fp16().blend(**kwargs).show_tfms()

uncomment and remove the resnet152 and you get the error.

rbunn80110 commented 5 years ago

I'm thinking a super simple notebook that uses this code would probably clear up my confusion on how to use this.

rbunn80110 commented 5 years ago

Apparently I need to use Learner and not cnn_learner:

learn = Learner(data, res2net(), metrics=[accuracy, dice, Precision(average='macro'),Recall(average='macro'),FBeta(average='macro')], callback_fns=[ShowGraph], wd=1e-3, bn_wd=False, true_wd=True, loss_func=LabelSmoothingCrossEntropy(), opt_func=optar).to_fp16()