computer-vision - 在 Colab 中使用“imgaug”进行图像数据增强未按预期工作
问题描述
我正在扩充我的图像数据集,其中也包含关键点。出于这个原因,我正在使用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 上使用这个版本,它对我来说没有问题。
推荐阅读
- javascript - 在 React Native 中正确显示我的徽标
- python - 仅将 2 个定义的列 html 表解析为字典以供以后使用
- chef-infra - Berkshelf:无法设置不受支持的配置值
- javascript - 在返回响应之前,是否可以通过持久连接发送第二个请求。节点.js
- php - 如何在 Symfony 4 中创建通用存储库
- excel - 使用宏用时间戳填充列
- vue.js - vuejs 递归单文件组件
- android - 为什么我在 Android Studio 中收到“未解析的引用:绑定”错误?
- c# - WPF QuickConverter:布尔值且不起作用
- javascript - Puppeteer 无法发布