ImageDataGenerator扩充数据集
keras在使用时候扩充数据集图片,但是图片出现了一定的问题,四周出现了长条状东西,更换了填充模式还是存在
import os
from keras.preprocessing.image import ImageDataGenerator,img_to_array,load_img
data_generator=ImageDataGenerator(
rotation_range=45,
width_shift_range=0.2,
height_shift_range=0.3,
brightness_range=(0.5,0.9),
zoom_range=[0.5,1.1],
horizontal_flip=True,
vertical_flip = True,
#fill_mode=' '
)
path=r"C:\Users\PC\Desktop\koutu\baiyunyan"
for i in os.listdir(path):
address=os.path.join(path,i)
img=load_img(address)
image=img_to_array(img)
image=image.reshape((1,)+image.shape)#需要四维
j=0
for i in data_generator.flow(image,batch_size=1,
save_to_dir=r"C:\Users\PC\Desktop\koutu\456",
save_prefix='baiyunyan',
save_format='png'):
j+=1
if(j>=5):
break;
print("全部完成")