数据增强简单方法

神经网络训练当中,训练数据数据是训练好一个优秀分类(检测)器最重要的部分之一,本文将简要描述一下一些常用的数据增强方法。

1. mix up

通过线性插值,构建以训练集中两个随机样本和对应标签的差值产生的虚拟样本,是领域风险最小化的一种方式。

数据增强简单方法

2. 旋转

cv2.flip(img,0)垂直翻转

cv2.flip(img,1)水平翻转

cv2.flip(img,-1)垂直水平翻转

3. 随机裁剪

tf.random_crop(reshaped_image,[height,width,3])

import numpy as np
import cv2
import tensorflow as tf
import matplotlib.pyplot as plt

sess = tf.InteractiveSession()
image = np.array(cv2.imread('test.jpg'))

reshape_img = tf.cast(image, tf.float32)
shape = tf.cast(tf.shape(reshape_img).eval(), tf.int32)
crop = tf.random_crop(reshape_img, [shape[0]/2,shape[1]/2,3])

fig = plt.figure()
fig1 = plt.figure()
ax = fig.add_subplot(111)
ax1 = fig1.add_subplot(111)
ax.imshow(sess.run(tf.cast(reshape_img,tf.uint8)))
ax1.imshow(sess.run(tf.cast(crop,tf.uint8)))

数据增强简单方法