我正在扩充我的图像数据集,其中也包含关键点。为此,我正在使用 imgaug
库。以下是增强代码:
kps = KeypointsOnImage(__keypoints, shape=_image.shape)
seq = iaa.Sequential([
iaa.Affine(
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis
translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
rotate=(-90, 90), # rotate by -45 to +45 degrees
order=[0, 1], # use nearest neighbour or bilinear interpolation (fast)
cval=(0, 255),
),
iaa.Fliplr(0.5),
], random_order=True)
# Augment keypoints and images.
image_aug, kps_aug = seq(image = _image, keypoints=kps)
但是在查看增强图像时我发现了以下问题:
- 有些图片没有任何关键点。
- 在一些增强图像中,关键点位于图像之外,尽管我一直在检查以阻止将那些增强输出保存在关键点不在图像内部的位置。
但奇怪的是,当我在我的 PC 上运行相同的代码时,它运行完全正常。但是当我在 Google-Colab 上运行它时,它会产生这些不需要的输出。为什么会这样?
最佳答案
我发现是版本问题。在 Colab 库中 imgaug
附带一个版本 0.2.9
但是这个版本会产生这些不需要的输出。所以我卸载了这个现有版本并安装了版本0.4.0
.虽然在安装时它显示了以下错误:
ERROR: albumentations 0.1.12 has requirement imgaug<0.2.7,>=0.2.5, but you'll have imgaug 0.4.0 which is incompatible.
但我忽略了它,对我来说它运行良好。以下是卸载现有版本并安装所需版本的代码:
!pip uninstall imgaug
!pip install imgaug==0.4.0
我安装的版本是0.4.0
因为我也在我的本地 PC 上使用这个版本,它对我来说没有问题。
关于computer-vision - 在 Colab 中,使用 "imgaug"进行图像数据增强未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62580797/