I'm running the detectron2 tutorial from the Google Colab link. But I'm facing a size mismatch error on the dataloader.
SizeMismatchError: Caught SizeMismatchError in DataLoader worker process 1.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/content/detectron2_repo/detectron2/data/common.py", line 39, in __getitem__
data = self._map_func(self._dataset[cur_idx])
File "/content/detectron2_repo/detectron2/utils/serialize.py", line 23, in __call__
return self._obj(*args, **kwargs)
File "/content/detectron2_repo/detectron2/data/dataset_mapper.py", line 76, in __call__
utils.check_image_size(dataset_dict, image)
File "/content/detectron2_repo/detectron2/data/detection_utils.py", line 73, in check_image_size
"mismatch (W,H), got {}, expect {}".format(image_wh, expected_wh)
detectron2.data.detection_utils.SizeMismatchError: mismatch (W,H), got (4128, 2322), expect (2322, 4128)
Update: I realized that PIL was not reading the exif data of my image and auto-rotating it for me. Whereas in cv2.imread(), it will just read the image as it is.
It is not swapped. It means the width and height in your annotation does not agree with what PIL thinks the size of your image is.
In case anyone else is facing this problem, you can address it using this.
Thank you. I had the same problem with 1366cde3b480a15c.jpg in the Open Images 2019 dataset. This image file is rotated by applying exif_transpose.
Most helpful comment
In case anyone else is facing this problem, you can address it using this.
https://stackoverflow.com/questions/13872331/rotating-an-image-with-orientation-specified-in-exif-using-python-without-pil-in