About the vision category

Topics related to either pytorch/vision or vision research related topics

1 Like

hallo, I am new to pytorch, but I am enjoying this framework. I am having diffeculty in figuring out this message.can anyone help please !!
RuntimeError: The size of tensor a (10) must match the size of tensor b (32) at non-singleton dimension 0
I did a bit of debugging and I found that there is a collapse of labels happening in labels tensors
[[[-1.0000, -1.0000, -1.0000, …, -1.0000, -1.0000, -1.0000],
[-1.0000, -1.0000, -1.0000, …, -1.0000, -1.0000, -1.0000],
[-1.0000, -1.0000, -1.0000, …, -1.0000, -1.0000, -1.0000],
…,
[-1.0000, -1.0000, -1.0000, …, -1.0000, -1.0000, -1.0000],
[-1.0000, -1.0000, -1.0000, …, -1.0000, -1.0000, -1.0000],
[-1.0000, -1.0000, -1.0000, …, -1.0000, -1.0000, -1.0000]]]]) tensor([9, 2, 1, 1, 6, 1, 4, 6, 5, 7, 4, 5, 7, 3, 4, 1, 2, 4, 8, 0, 2, 5, 7, 9,
1, 4, 6, 0, 9, 3, 8, 8])

I created my model from scratch . I tried with batch_size 32 , it threw me this error. I tried with batch_size 1 , I got 320% accuracy (something wrong !). The error went away. so there is some dimensional mismatch some where, I am lost! thanks a million !!! for your help and advise

can we see your Model ?

Hi, if you jumped in too fast as far as model building goes, don’t be discouraged. A few months ago, I tried building a model without reading the documentation entirely. Now that I’ve ingested a lot of the documentation, I’m feeling a lot more confident about building models in PyTorch, and to be honest… that seems like the least of what i will be able to do soon, in PyTorch

So my best advice is if you need help, is to read the documentation, and you’ll be able to really receive the fruits from your reading soon!

from what is available I can see that your model output has different number of dimensions from your labels… here is an example for you to understand their structure better.

import torch
model_output = torch.randn((32,10))
print(model_output.size())#this will be the model outputs size

label = torch.randn((10))
print(label.size())#this will be the label size

assume that 32 is the batch size so your labels also should have the same dimension in order to get the results you are looking for. when you are creating or loading your data make sure that you have the correct corresponding label along with it.
please let me know if you need further assistance.