我想提一下,变换前图像的形状是:
| | Shape |
| --|--|
| 原始图像|(360,640,3)|
| 原始掩膜|(360,640)|
| 变换图像|(320,320,3)|
| 变换掩模|(320,320)|img_trans
定义为:
img_trans = A.Compose([
A.Resize(a_config.INPUT_IMAGE_HEIGHT, a_config.INPUT_IMAGE_WIDTH)],
is_check_shapes=False
)
字符串
代码片段是:
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
型
但我得到了一个错误:
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)..
型
我不确定我是否得到了错误,因为最初的第三维是图像而不是掩码。因此,我试图在定义img_trans
时添加is_check_shapes=False
,但我仍然得到错误。
你能建议我是否应该在哪里添加is_check_shapes=False
,或者错误可以通过其他方式解决吗?
1条答案
按热度按时间tsm1rwdh1#
这是旧的,但我有一个问题,我在执行转换之前改变了我的图像/遮罩的尺寸。在我的例子中,我在我的pytorch数据集中转换之前先将图像转换为通道。
我有这个:
字符串
我本该得到这个的
型