OpenCV Warpaffine错误在图像增强期间使用符号符号
我一直在尝试使用名为Albimodations的库进行图像增强。但是在转换图像时,我从OpenCV中遇到了一些错误。我在Kaggle的笔记本上运行了下面的代码。该数据集在Kaggle上称为“英特尔图像分类”。它有6堂课。每个图像为150 * 150 * 3。
import numpy as np
import tensorflow as tf
import albumentations as a
x_train_path = "../input/intel-image-classification/seg_train/seg_train"
train_data = tf.keras.utils.image_dataset_from_directory(
x_train_path,
seed=123,
image_size=(150, 150),
batch_size=128)
transforms = Compose([
a.Rotate(limit=40),
a.HueSaturationValue(hue_shift_limit=20, sat_shift_limit=30, val_shift_limit=20, p=0.5),
a.GaussianBlur(p=0.5),
a.RandomContrast(limit=0.2, p=0.5),
a.RandomBrightnessContrast(brightness_limit=0.3, contrast_limit=0.3),
a.HorizontalFlip(),
])
#looping through the train_data generator
for image,label in train_data:
#albumentations requires data to be numpy array and dtype uint8
image = tf.cast(image,tf.uint8).numpy()
aug_image = transforms(image=image) # ERROR HERE
print(aug_image)
break
这是整个错误:
error Traceback (most recent call last)
/tmp/ipykernel_33/2678995032.py in <module>
7
8
----> 9 aug_image = transforms(image=image)
10 print(aug_image)
11 break
/opt/conda/lib/python3.7/site-packages/albumentations/core/composition.py in __call__(self, force_apply, *args, **data)
208
209 for idx, t in enumerate(transforms):
--> 210 data = t(force_apply=force_apply, **data)
211
212 if check_each_transform:
/opt/conda/lib/python3.7/site-packages/albumentations/core/transforms_interface.py in __call__(self, force_apply, *args, **kwargs)
95 )
96 kwargs[self.save_key][id(self)] = deepcopy(params)
---> 97 return self.apply_with_params(params, **kwargs)
98
99 return kwargs
/opt/conda/lib/python3.7/site-packages/albumentations/core/transforms_interface.py in apply_with_params(self, params, force_apply, **kwargs)
110 target_function = self._get_target_function(key)
111 target_dependencies = {k: kwargs[k] for k in self.target_dependence.get(key, [])}
--> 112 res[key] = target_function(arg, **dict(params, **target_dependencies))
113 else:
114 res[key] = None
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/geometric/rotate.py in apply(self, img, angle, interpolation, **params)
86
87 def apply(self, img, angle=0, interpolation=cv2.INTER_LINEAR, **params):
---> 88 return F.rotate(img, angle, interpolation, self.border_mode, self.value)
89
90 def apply_to_mask(self, img, angle=0, **params):
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/functional.py in wrapped_function(img, *args, **kwargs)
68 def wrapped_function(img, *args, **kwargs):
69 shape = img.shape
---> 70 result = func(img, *args, **kwargs)
71 if len(shape) == 3 and shape[-1] == 1 and len(result.shape) == 2:
72 result = np.expand_dims(result, axis=-1)
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/geometric/functional.py in rotate(img, angle, interpolation, border_mode, value)
77 cv2.warpAffine, M=matrix, dsize=(width, height), flags=interpolation, borderMode=border_mode, borderValue=value
78 )
---> 79 return warp_fn(img)
80
81
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/functional.py in __process_fn(img)
187 img = np.dstack(chunks)
188 else:
--> 189 img = process_fn(img, **kwargs)
190 return img
191
error: OpenCV(4.5.4) /tmp/pip-req-build-21t5esfk/opencv/modules/imgproc/src/imgwarp.cpp:2595: error: (-215:Assertion failed) src.cols > 0 && src.rows > 0 in function 'warpAffine'
I have been trying to do image augmentation using a library called Albumentations. But I got some error from OpenCV while transforming the images. I ran the code below on Kaggle's notebook. The dataset is called "Intel image classification" on kaggle. It has 6 classes. Each image is 150 * 150 * 3.
import numpy as np
import tensorflow as tf
import albumentations as a
x_train_path = "../input/intel-image-classification/seg_train/seg_train"
train_data = tf.keras.utils.image_dataset_from_directory(
x_train_path,
seed=123,
image_size=(150, 150),
batch_size=128)
transforms = Compose([
a.Rotate(limit=40),
a.HueSaturationValue(hue_shift_limit=20, sat_shift_limit=30, val_shift_limit=20, p=0.5),
a.GaussianBlur(p=0.5),
a.RandomContrast(limit=0.2, p=0.5),
a.RandomBrightnessContrast(brightness_limit=0.3, contrast_limit=0.3),
a.HorizontalFlip(),
])
#looping through the train_data generator
for image,label in train_data:
#albumentations requires data to be numpy array and dtype uint8
image = tf.cast(image,tf.uint8).numpy()
aug_image = transforms(image=image) # ERROR HERE
print(aug_image)
break
Here is the whole error:
error Traceback (most recent call last)
/tmp/ipykernel_33/2678995032.py in <module>
7
8
----> 9 aug_image = transforms(image=image)
10 print(aug_image)
11 break
/opt/conda/lib/python3.7/site-packages/albumentations/core/composition.py in __call__(self, force_apply, *args, **data)
208
209 for idx, t in enumerate(transforms):
--> 210 data = t(force_apply=force_apply, **data)
211
212 if check_each_transform:
/opt/conda/lib/python3.7/site-packages/albumentations/core/transforms_interface.py in __call__(self, force_apply, *args, **kwargs)
95 )
96 kwargs[self.save_key][id(self)] = deepcopy(params)
---> 97 return self.apply_with_params(params, **kwargs)
98
99 return kwargs
/opt/conda/lib/python3.7/site-packages/albumentations/core/transforms_interface.py in apply_with_params(self, params, force_apply, **kwargs)
110 target_function = self._get_target_function(key)
111 target_dependencies = {k: kwargs[k] for k in self.target_dependence.get(key, [])}
--> 112 res[key] = target_function(arg, **dict(params, **target_dependencies))
113 else:
114 res[key] = None
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/geometric/rotate.py in apply(self, img, angle, interpolation, **params)
86
87 def apply(self, img, angle=0, interpolation=cv2.INTER_LINEAR, **params):
---> 88 return F.rotate(img, angle, interpolation, self.border_mode, self.value)
89
90 def apply_to_mask(self, img, angle=0, **params):
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/functional.py in wrapped_function(img, *args, **kwargs)
68 def wrapped_function(img, *args, **kwargs):
69 shape = img.shape
---> 70 result = func(img, *args, **kwargs)
71 if len(shape) == 3 and shape[-1] == 1 and len(result.shape) == 2:
72 result = np.expand_dims(result, axis=-1)
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/geometric/functional.py in rotate(img, angle, interpolation, border_mode, value)
77 cv2.warpAffine, M=matrix, dsize=(width, height), flags=interpolation, borderMode=border_mode, borderValue=value
78 )
---> 79 return warp_fn(img)
80
81
/opt/conda/lib/python3.7/site-packages/albumentations/augmentations/functional.py in __process_fn(img)
187 img = np.dstack(chunks)
188 else:
--> 189 img = process_fn(img, **kwargs)
190 return img
191
error: OpenCV(4.5.4) /tmp/pip-req-build-21t5esfk/opencv/modules/imgproc/src/imgwarp.cpp:2595: error: (-215:Assertion failed) src.cols > 0 && src.rows > 0 in function 'warpAffine'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论