What is the size of the images in your batch? You may need to resize your images using a transform in your dataset before they can be fed into the network. I would guess that the error is telling you that the height dimensions of some of your images in the batch are not equal.
They don’t need to be squared per se, but all the images in your batch need to be the same to allow for batch processing.
For example this is a standard transform that would resize the images to be 224x224 and make it suitable for a imagenet trained classifier:
this would then be passed into the transforms argument when you create your dataset and would resize and make those other transformations for you as well. You can see a worked out example of how this works at https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html.