【发布时间】:2020-03-01 23:19:13
【问题描述】:
如何为文件夹中存储的多张图像应用 Keras Image Augmentation?
P.S:我为单个图像尝试了以下代码,效果很好。
有人可以帮我解决多张图片吗??
enter code here
from keras.preprocessing import image
import matplotlib.pyplot as plt
import cv2
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
rotation_range = 30,
width_shift_range = 0.2,
height_shift_range = 0.2,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = 0.2,
fill_mode = "nearest")
for img in glob.glob("Images/*/*.jpg"):
cv_img = cv2.imread(img)
cv_resize = cv2.resize(cv_img,(200,200))
cv_norm_img = cv_resize/255.0
break
cv_norm_img = np.array(cv_norm_img)
input_batch = cv_norm_img.reshape((1,*cv_norm_img.shape))
i = 0
for output_batch in datagen.flow(input_batch,batch_size=1):
plt.figure()
imgplot = plt.imshow(image.img_to_array(output_batch[0]))
i+=1
if i==10:
break
plt.axis('off')
plt.show
【问题讨论】:
标签: python image image-processing keras