欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

深度学习-数据增广

程序员文章站 2022-07-12 22:56:17
...

import os
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

datagen = ImageDataGenerator(
featurewise_center=False,
rotation_range=16,
rescale=1./255,
width_shift_range=0,
height_shift_range=0,
shear_range=0.1,
zoom_range=0.1,
horizontal_flip=False,
vertical_flip = True,
fill_mode=‘nearest’)
for file_name in os.listdir(‘C:/Users/Administrator/Desktop/dataset_self/train_cashang’):
img = load_img(‘C:/Users/Administrator/Desktop/dataset_self/train_cashang/’+file_name)
x = img_to_array(img)
x = x.reshape((1,) + x.shape)

i = 1
j = 1
for batch in datagen.flow(x,
	batch_size = 8,
	save_to_dir = 'C:/Users/Administrator/Desktop/dataset_self/train_cashang/',
	save_prefix = 'cashang',
	save_format = '.jpg'):
	i += 1
	if i > 5:
		break
		j += 1
		if j > 5:
			break