Hi.
I’m going through the Practical Deep Learning for coders and I’m getting the following error:
Traceback (most recent call last):
File "/home/onur/Documents/fastai-deep-learning/Model.py", line 16, in <module>
learn = cnn_learner(data, models.resnet34(), metrics=error_rate)
File "/home/onur/anaconda3/lib/python3.7/site-packages/fastai/vision/learner.py", line 98, in cnn_learner
bn_final=bn_final, concat_pool=concat_pool)
File "/home/onur/anaconda3/lib/python3.7/site-packages/fastai/vision/learner.py", line 84, in create_cnn_model
body = create_body(base_arch, pretrained, cut)
File "/home/onur/anaconda3/lib/python3.7/site-packages/fastai/vision/learner.py", line 56, in create_body
model = arch(pretrained)
File "/home/onur/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/onur/anaconda3/lib/python3.7/site-packages/torchvision/models/resnet.py", line 216, in forward
return self._forward_impl(x)
File "/home/onur/anaconda3/lib/python3.7/site-packages/torchvision/models/resnet.py", line 199, in _forward_impl
x = self.conv1(x)
File "/home/onur/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/onur/anaconda3/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 345, in forward
return self.conv2d_forward(input, self.weight)
File "/home/onur/anaconda3/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 342, in conv2d_forward
self.padding, self.dilation, self.groups)
TypeError: conv2d(): argument 'input' (position 1) must be Tensor, not bool
I looked up the problem and saw that other students were having the same issue. However, I couldn’t really make sense of the suggested solutions. I’m very new to this. The following is my code so far:
from fastai import *
from fastai.vision import *
from pathlib import Path
image_path = Path("images")
fnames = get_image_files(image_path)
# The regular expression will be used to get the image names
file_parse = r'/([^/]+)_\d+.jpg$'
# ImageDataBunch.from_name_re extracts the names of the images and assings them as the labels for the images
# Size=224 turns each image to the same size, in this case, 224
data = ImageDataBunch.from_name_re(image_path, fnames, file_parse, ds_tfms=get_transforms(), size=224)
data.normalize(imagenet_stats)
learn = cnn_learner(data, models.resnet34(), metrics=error_rate)
learn.fit_one_cycle(4)