from keras.preprocessing.image import ImageDataGenerator
from keras.preprocessing import image
img_genarator = ImageDataGenerator(rotation_range = 50,
width_shift_range = 0.2,
height_shift_range = 0.2,
shear_range = 0.2,
zoom_range = 0.3,
horizontal_flip = True,
fill_mode = 'nearest'
)
for i in range(0,len(train_images_list)):
img = image.load_img('/home/yuejian/Desktop/huaweiYUN/train_images/'+train_images_list[i])
content=train_images_list[i].split('_')
print(i)
# 将图片转换为数组,并重新设定形状
x = image.img_to_array(img)
x = x.reshape((1,) + x.shape)
# x的形状重组为(1,width,height,channels),第一个参数为batch_size
# 这里人工设置停止生成, 并保存图片用于可视化
j = 0
for batch in img_genarator.flow(x,batch_size=1,save_to_dir='/home/yuejian/Desktop/huaweiYUN/train_images_gen',save_prefix=content[0],save_format='png'):
j +=1
if j > 9:
break # 如果不设置,生成器会不断的生成图片
训练图片生成,图片增强
最新推荐文章于 2023-07-27 20:59:19 发布