众所周知,数据对于神经网络的训练至关重要。一般来说,原始数据量越大,训练出来的模型精度越高,泛化能力越强。但是,做数据标注费时费力,往往不容易收集太多。利用已有的数据,通过翻转等数据处理,可以制造出更多的图片,进而提高网络的精度和泛化能力。


1.从github上下载源代码。


git clone https://github.com/aleju/imgaug.git

2.制作说明文档

cd imgaug/docs

make html

    报错:/usr/bin/python: No module named sphinx

    解决:sudo pip install sphinx

    报错:exception: No module named numpydoc

    解决:sudo pip install  numpydoc

                sudo pip install sphinx_rtd_theme



再次:

make html

编译成功后,打开 ./docs/_build/html/index.html,出现如下的网页,意味着说明书制作成功。







3.安装

查看"installation"安装说明,选择一种方式安装,我用的是:

 sudo pip install imgaug

检验是否安装成功,在终端中输入: python

然后:
import imgaug 未报错,证明已经安装成功。
4.测试程序

参照说明书中的Examples:basics,处理一张本地的图片,程序如下:


#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Mar 26
15:26:49 2018 @author: user """ from imgaug import augmenters as iaa import cv2
seq = iaa.Sequential([ iaa.Crop(px=(0, 16)), # crop images from each side by 0
to 16px (randomly chosen) iaa.Fliplr(0.5), # horizontally flip 50% of the images
iaa.GaussianBlur(sigma=(0, 3.0)) # blur images with a sigma of 0 to 3.0 ])
imglist=[]#for batch_idx in range(1000): # 'images' should be either a 4D
numpy array of shape (N, height, width, channels) # or a list of 3D numpy
arrays, each having shape (height, width, channels). # Grayscale images must
have shape (height, width, 1) each. # All images must have numpy's dtype uint8.
Values are expected to be in # range 0-255. img = cv2.imread(
'/home/thm/imgaug/imgaug/quokka.jpg') #images = load_batch(batch_idx)
imglist.append(img) images_aug = seq.augment_images(imglist) cv2.imwrite('
/home/thm/imgaug/imgaug/quokka_.jpg',images_aug[0]#train_on_images(images_aug)
 
结果:

原图



处理后:






其他的处理方法大家可以动手实践。



https://github.com/aleju/imgaug4

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信