RuntimeError: The size of tensor a (1000) must match the size of tensor b (10) at non-singleton dimension 1

Hi Guys,

I have a pre-trained resnet-50 model, which upon training gives this error: The size of tensor a (1000) must match the size of tensor b (10) at non-singleton dimension 1.
I am using MSELoss.


for epoch in range(n_epochs):
    N = len(train_loader)
    epoch_train_loss, epoch_test_loss = 0, 0
    val_age_mse, ctr = 0, 0
    _n = len(train_loader)
    for ix, data in enumerate(train_loader):
        # if ix == 100: break
        **loss = train_batch(data, model, optimizer, criteria)** (This is where error shows up)
        epoch_train_loss += loss.item()

This is where error crops up:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-103-01cf2dc1c2bf> in <module>()
     30     for ix, data in enumerate(train_loader):
     31         # if ix == 100: break
---> 32         loss = train_batch(data, model, optimizer, criteria)
     33         epoch_train_loss += loss.item()
     34 

4 frames
/usr/local/lib/python3.7/dist-packages/torch/functional.py in broadcast_tensors(*tensors)
     69         if any(type(t) is not Tensor for t in tensors) and has_torch_function(tensors):
     70             return handle_torch_function(broadcast_tensors, tensors, *tensors)
---> 71     return _VF.broadcast_tensors(tensors)  # type: ignore

Can you show your train_batch function and the entire error. Can you also print out the shapes of your inputs and labels.