我正在使用albumentations 将转换应用于Pytorch 模型,但出现此错误,我没有得到任何关于此错误的线索。我只知道这是由于正在应用的转换而发生的,但不确定这有什么问题。
ValueError: Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/opt/conda/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 99, in <listcomp>
samples = collate_fn([dataset[i] for i in batch_indices])
File "<ipython-input-23-119ea6bc360e>", line 24, in __getitem__
image = self.transform(image)
File "/opt/conda/lib/python3.6/site-packages/albumentations/core/composition.py", line 164, in __call__
need_to_run = force_apply or random.random() < self.p
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
这是代码片段。数据加载器 getitem ( ) 方法:
image = cv2.imread(p_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = crop_image_from_gray(image)
image = cv2.resize(image, (IMG_SIZE, IMG_SIZE))
image = cv2.addWeighted ( image,4, cv2.GaussianBlur( image , (0,0) , 10) ,-4 ,128)
print(image.shape)
image = self.transform(image)
应用变换:
val_transform = albumentations.Compose([
Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225],
),
ToTensor()
])
该类由以下人员调用:
valset = MyDataset(val_df, transform = val_transform)