RuntimeError: Function AddmmBackward returned an invalid gradient at index 1 - got [10, 512] but expected shape compatible with [10, 25088]

Hey guys, I keep encountering this error in my code even though I have I have entered the right input_channel number and output.

Can’t see the error mentioned, but for the present one in notebook:

Torch models working with images expect the input to be a batch of images.

You need to convert your image (3-dimensional tensor) into a batch (4-dimensional tensor).

You can do so with unsqueeze().

1 Like

thank you for your reply, I have found the issue, there was a problem in the architecture of the model, but it seems that there is another problem I can’t find the cause.

When using random_split a Subset class is returned.

To access the dataset from Subset you can use dataset attribute.

The dataset although is a whole dataset (the one you used before splitting), so it has all examples.
But since you care here only for a class name for given label, it should work without problems.

1 Like

so how should I access classes

for this you have to split your datasets using random_split.

yes, but I can’t make predictions on single images.

can you share me your code, i will check it.