I trained a model using the MNIST_SAMPLE (3s and 7 digits).
path = untar_data(URLs.MNIST_SAMPLE)
dls = ImageDataLoaders.from_folder(path)
learn=cnn_learner(dls,resnet18,pretrained=False,loss_func=F.cross_entropy,metrics = accuracy)
learn.fit_one_cycle(1,0.1)
Now I wish to test this model on a single image.
I upload the images:
threes = (path/'train'/'3').ls()
threes_data = [Image.open(i) for i in threes]
tensor_3 =[tensor(i).float()/255 for i in threes_data]
img = tensor_3[0]
Prediction:
learn.predict(img)
Getting the following error message:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/fastai/learner.py in with_events(self, f, event_type, ex, final)
154 def with_events(self, f, event_type, ex, final=noop):
–> 155 try: self(f’before{event_type}’) ;f()
156 except ex: self(f’after_cancel{event_type}’)
30 frames
RuntimeError: Given groups=1, weight of size [64, 3, 7, 7], expected input[1, 1, 28, 28] to have 3 channels, but got 1 channels instead
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
TypeError: expected Tensor as element 0 in argument 0, but got NoneType
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/fastcore/utils.py in range_of(x)
209 def range_of(x):
210 "All indices of collection `x` (i.e. `list(range(len(x)))`)"
--> 211 return list(range(len(x)))
212
213 # Cell
TypeError: object of type 'NoneType' has no len()