If your images are of different sizes and not squares, the smaller edge is matched to the given size, which means that in this case there is no guarantee that all images have all edges of the same size.
See here: https://pytorch.org/docs/stable/torchvision/transforms.html#torchvision.transforms.Resize 300