Inconsistent Tensor Sizes

I am implementing VQA in pytorch and I am getting this error when I train the model.

RuntimeError: inconsistent tensor sizes at /pytorch/torch/lib/TH/generic/THTensorMath.c:2864

The loss decreases for certain batches, but then I get this error. Can anyone tell me what the problem is?

I am attaching my code below.

I solved it. The image dimensions were not consistent. Just converted them to an RGB format.