@BruceWang
2018-01-08T22:01:47.000000Z
字数 1742
阅读 1617
数据增强
[TOC]
# _*_ coding:utf-8 _*_
"""
Deep learning image augmentation
cited from https://scottontechnology.com/flip-image-opencv-python/
http://augmentor.readthedocs.io/en/master/userguide/mainfeatures.html
"""
import cv2
import glob
import random
import os
from multiprocessing import Pool as ProcessPool
from multiprocessing.dummy import Pool as ThreadPool
import Augmentor
import numpy as np
def augmentation():
path = r'C:\Users\aixin\Desktop\all_my_learning\match\niu_qu\original_path'
output_path = r'C:\Users\aixin\Desktop\all_my_learning\match\niu_qu\niuqu_path'
p = Augmentor.Pipeline(path, output_directory=output_path)
# p.flip_left_right(probability=0.4)
# p.flip_top_bottom(probability=0.6)
# p.flip_random(probability=0.5)
# p.crop_centre(probability=0.2, percentage_area=0.8)
# p.crop_random(probability=0.6, percentage_area=0.7)
# p.rotate(probability=0.2, max_left_rotation=10, max_right_rotation=16)
# p.rotate_random_90(probability=0.5)
# p.rotate180(probability=0.4)
# p.rotate270(probability=0.3)
p.zoom(probability=0.3, min_factor=1.1, max_factor=1.5)
p.random_distortion(probability=0.5, grid_height=4, grid_width=4, magnitude=4)
p.shear(probability=0.2, max_shear_left=15, max_shear_right=15)
p.shear(probability=0.5, max_shear_left=15, max_shear_right=15)
p.skew(probability=0.1, magnitude=0.6)
p.skew_tilt(probability=0.2, magnitude=0.6)
p.skew_corner(probability=0.2, magnitude=0.6)
p.skew_top_bottom(probability=0.3, magnitude=0.6)
p.skew_left_right(probability=0.2, magnitude=0.6)
# SIZE = 4 * 5
# 这里的size表示的是random_distortion随机产生的扩展个数
p.sample(10)
if __name__ == '__main__':
augmentation()
pass
如果你有什么疑问,欢迎联系我哈,我会给大家慢慢解答啦~~~
怎么联系我? 笨啊~ ~~ 你留言也行。
你关注微信公众号1.听朕给你说:2.tzgns666,3.或者扫那个二维码,后台联系我也行啦!
(爱心.gif) 么么哒~么么哒~么么哒
爱心从我做起,贫困山区捐衣服,为开源社区做贡献!码字不易啊,如果你觉得本文有帮助,三毛也是爱!真的就三毛,呜呜。。。我祝各位帅哥,和美女,你们永远十八岁,嗨嘿嘿~~~