Torchvision and dataloader different images shapes

hi,
yes, cnn, and pytorch modules, generally operate on tensors not lists.
the example above of the model is meant for the evaluation primarily. although, it could work for training but there may be a gradient issue.

so, in order to process a list of tensors of different shapes without changing your model, you can do the following:

  1. the list needs to contain tensors. do not feed the list to the model. the collate function above allows to build such list.
  2. you need to loop over the list OUTSIDE the model. for each loop, you will get a tensor from the list. feed that tensor to your model.
  3. you need to accumulate the gradient (for training). please see here two ways for gradient accumulation. each tensor in the list could be one single sample or a tiny mini-batch. make sure to divide the loss by the true total number of samples after forwarding all the tensors.
    thanks
1 Like