Problem CNN picture

how to display a picture with deep learning

print('Validation accuracy test: {:.4f}%'.format(float(accuracy_score(val_y, predictions)) * 100))
conf_matrix  = confusion_matrix(val_y, predictions)
print(conf_matrix)
plt.imshow(torchvision.utils.make_grid(predictions))  

Error :

TypeError                                 Traceback (most recent call last)
<ipython-input-8-767abd2c3c6d> in <module>()
    402 
    403 print(conf_matrix)
--> 404 plt.imshow(torchvision.utils.make_grid(predictions))

1 frames
/usr/local/lib/python3.7/dist-packages/torchvision/utils.py in make_grid(tensor, nrow, padding, normalize, value_range, scale_each, pad_value, **kwargs)
     44     if not (torch.is_tensor(tensor) or
     45             (isinstance(tensor, list) and all(torch.is_tensor(t) for t in tensor))):
---> 46         raise TypeError(f'tensor or list of tensors expected, got {type(tensor)}')
     47 
     48     if "range" in kwargs.keys():

TypeError: tensor or list of tensors expected, got <class 'numpy.ndarray'>

Help me plzzz

make_grid expects a 4D tensor or a list of of images as described in the docs:

tensor (Tensor or list) – 4D mini-batch Tensor of shape (B x C x H x W) or a list of images all of the same size.

while you are trying to pass a numpy array to it.

thank you for your reply @ptrblck

But when I tested this :

conf_matrix  = confusion_matrix(val_y, predictions)

        

print(conf_matrix)

plt.imshow(torchvision.utils.make_grid((predictions, nrow: int = 8, padding: int = 2, normalize: bool = False, value_range: Optional[Tuple[int, int]] = None, scale_each: bool = False, pad_value: int = 0, **kwargs))

Error :

File “”, line 403
plt.imshow(torchvision.utils.make_grid((predictions, nrow: int = 8, padding: int = 2, normalize: bool = False, value_range: Optional[Tuple[int, int]] = None, scale_each: bool = False, pad_value: int = 0, **kwargs))
^
SyntaxError: invalid syntax

It seems you might have just copied the arguments from the docs without defining them.
This would work:

predictions = torch.randn(4, 3, 224, 224)
plt.imshow(torchvision.utils.make_grid(predictions).permute(1, 2, 0))  

Thank you @ptrblck but how to save the image in extension .mat? plzz

scipy.io.savemat should work.