I would like to mention that the shape of image before transformation is:
| Shape | |
|---|---|
| Original image | (360, 640, 3) |
| Original mask | (360, 640) |
| Transformed image | (320, 320, 3) |
| Transformed mask | (320, 320) |
and img_trans is defined as
img_trans = A.Compose([
A.Resize(a_config.INPUT_IMAGE_HEIGHT, a_config.INPUT_IMAGE_WIDTH)],
is_check_shapes=False
)
The code snippet is:
def image_mask_transformation(image, mask, img_trans, aug_trans=None, normalize=True,
var_min=10, var_max=400):
print("Original image shape:", image.shape)
transformed = img_trans(image=image, mask=mask)
image = transformed["image"]
mask = transformed["mask"]
print("transformed image shape:", image.shape)
# image, mask still uint 8 in 0, 255 range
But I am getting an error:
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/content/drive/MyDrive/Colab Notebooks/CRACK500/tool/dataset.py", line 131, in __getitem__
image_store, mask_store = image_mask_transformation(image, mask, self.img_trans, aug_trans=self.aug_trans,
File "/content/drive/MyDrive/Colab Notebooks/CRACK500/tool/dataset.py", line 40, in image_mask_transformation
transformed = img_trans(image=image, mask=mask)
File "/usr/local/lib/python3.10/dist-packages/albumentations/core/composition.py", line 195, in __call__
self._check_args(**data)
File "/usr/local/lib/python3.10/dist-packages/albumentations/core/composition.py", line 286, in _check_args
raise ValueError(
ValueError: Height and Width of image, mask or masks should be equal. You can disable shapes check by setting a parameter is_check_shapes=False of Compose class (do it only if you are sure about your data consistency)..
I am not sure whether I am getting the error because initially a 3rd dimension is there for image and not for the mask. Hence I have tried to add the is_check_shapes=False while defining img_trans but I am still getting the error.
Can you suggest whether and where I should add is_check_shapes=False or the error can be solved in any other way?
This is old now, but I had a problem where I was changing the dimensions of my image/mask before I performed the transforms. In my case, I was converting my images to channel first before transforming in my pytorch Dataset.
I had this:
when I should have had this: