Augmentor:数据增强工具库
github地址:https://github.com/mdbloice/Augmentor
一.安装:
pip install Augmentor
二.使用:
1.载入包,设置路径:
import Augmentor
p=Augmentor.Pipeline("./test")
回车之后,默认会生成输出的路径,在./test/output下,output文件夹自动生成,不需要自己新建。
2.图片逆时针随机旋转90度(随机概率可自行设定),p.sample(200)指生成200张这样操作的图片,这条语句可以在指定所有操作之后再运行,否则只会进行旋转90度这个操作
p.rotate90(probability=0.5)
p.sample(200)
3.图片顺时针随机旋转90度(随机概率可自行设定)
p.rotate270(probability=0.5)
p.sample(200)
4 .不固定角度微小旋转:比如向左最大旋转25度,向右最大旋转10度(备注:旋转最大角度范围是0-25度)
p.rotate(probability=0.5,max_left_rotation=25,max_right_rotation=10)
p.sample(200)
5.透视形变-垂直方向形变:magnitude取(0,1),指的是形变程度
p.skew_tilt(probability=0.7,magnitude=1)
p.sample(200)
6.透视形变-斜四角形变形变:magnitude取(0,1),指的是形变程度
p.skew_corner(probability=0.7,magnitude=1)
p.sample(200)
7.弹性扭曲,类似区域扭曲的感觉
p.random_distortion(probability=1,grid_height=5,grid_width=16,magnitude=8)
p.sample(200)
8.错切变换
p.shear(probability=1,max_shear_left=15,max_shear_right=15)
p.sample(200)
9.随机区域擦除
p.random_erasing(probability=1,rectangle_area=0.5)
p.sample(200)
10.组合上述操作的增强
import Augmentor
p=Augmentor.Pipeline("./test")
p.random_erasing(probability=1,rectangle_area=0.5)
p.random_distortion(probability=1,grid_height=5,grid_width=16,magnitude=8)
p.shear(probability=1,max_shear_left=15,max_shear_right=15)
p.sample(200)