6

图像分割 语义分割 Augmentor数据增强(数据扩充)

 1 year ago
source link: https://blog.51cto.com/husheng/5918792
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Table of Contents

1. Augmentor

Augmentor is an image augmentation library in Python for machine learning. It aims to be a standalone library that is platform and framework independent, which is more convenient, allows for finer grained control over augmentation, and implements the most real-world relevant augmentation techniques. It employs a stochastic approach using building blocks that allow for operations to be pieced together in a pipeline.
Augmentor是Python中用于机器学习的图像增强库。它的目标是成为一个独立于平台和框架的独立库,这更方便,允许对增强进行更精细的控制,并实现最真实的相关增强技术。它采用随机方法,使用构建块,允许在管道中将操作拼凑在一起。
Augmentor的目的是自动化图像增强(人工数据生成),以便扩展数据集作为机器学习算法的输入,尤其是神经网络和深度学习。
该包的工作原理是构建扩充管道,您可以在其中定义一系列要对一组图像执行的操作。旋转或转换等操作将逐个添加以创建扩充管道:完成后,可以执行管道并创建增强数据集。

一句话:使用Augmentor创建一个对象,向对象里添加各种带有概率值和参数的图像操作,使用该对象处理你的原始图像。

安装:pip install Augmentor
 GitHub源码
 帮助文档

2. 数据增强代码

# 导入数据增强工具
import Augmentor

# 确定原始图像存储路径以及掩码mask文件存储路径
p = Augmentor.Pipeline("demo1")
p.ground_truth("demo2")

# 图像旋转:按照概率0.8执行,最大左旋角度10,最大右旋角度10
# rotate操作默认在对原图像进行旋转之后进行裁剪,输出与原图像同样大小的增强图像
p.rotate(probability=0.8, max_left_rotation=10, max_right_rotation=10)

@[toc]
# 图像上下镜像: 按照概率0.5执行
p.flip_top_bottom(probability=0.5)

# 图像左右镜像: 按照概率0.5执行
p.flip_left_right(probability=0.5)

# 图像等比缩放,按照概率1执行,整个图片放大,像素变多
# p.scale(probability=1, scale_factor=1.3)

# 图像放大:放大后像素不变,先根据percentage_area放大,后按照原图像素大小进行裁剪
# 按照概率0.4执行,面积为原始图0.9倍
p.zoom_random(probability=0.4, percentage_area=0.9)

# 最终扩充的数据样本数
p.sample(200)

demo1文件夹下的output文件包含最终扩充的数据样本数的所有文件

3. 问题解决

output文件只有原图的增强,只有demo1中原图的数据增强文件,没有demo2中的mask文件的数据增强文件
原因:demo1和demo2中的文件,文件名不一致,需修改为文件名及扩展名都一致。

 参考博客


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK