Mat1 and mat2 shapes can't be multiplied

This is what I got out before a long list of errors:

<class 'PIL.JpegImagePlugin.JpegImageFile'>

Edit: This is also the error:

TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'PIL.JpegImagePlugin.JpegImageFile'>

The current issue looks like it may be coming from the dataset definition as it is not converting to a format that the default collate function can, well, collate. You can likely fix this by adding the to_tensor transformation to the dataset like this example.

I’ve done a little fiddling ended where this entire thing started.

RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x1 and 150528x300)

The code is following and I use PIL to open the image, make it a tensor, unsqueeze it then make it a float.
The relevant code follows:

imagetun = torch.tensor(imagepre)
image = (imagetun).unsqueeze(0)
image = image.float()
PRED = model(image)

Something is strange here because your resulting image shape is now 1x1. Can you check the intermediate shapes at each step? e.g., imagetun.shape and image.shape after each operation?

Since this looks like a pretty standard vision classification model, please take a look at the MNIST example. It is a good template to base a simple classification model on, particularly the data loading pipeline which seems to be the main issue here.

Well imagetun =


Whatever that means
and the following tensors after that are


. What have I done wrong?
Also, what library would be the most suitable for such a task to open the pictures in?

Please take a look at the MNIST and ImageNet examples as they show great examples of how typical classification model training pipelines are built. You can likely use the ImageFolder dataset class as is done in the ImageNet example.