pythonkeras数据增强_Keras数据增强参数
我在Keras中讀過一些關于數據擴充的資料,但對我來說還是有點模糊。在數據擴充步驟中,是否有任何參數來控制從每個輸入圖像創建的圖像的數量?在this example中,我看不到任何控制從每個圖像創建的圖像數量的參數。在
例如,在下面的代碼中,我可以使用一個參數(num_imgs)來控制從每個輸入圖像創建并存儲在名為preview的文件夾中的圖像數量;但是在實時數據擴充中,沒有任何參數用于此目的。在from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
num_imgs = 20
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
img = load_img('data/train/cats/cat.0.jpg') # this is a PIL image
x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape) # this is a Numpy array with shape (1, 3, 150, 150)
# the .flow() command below generates batches of randomly transformed images
# and saves the results to the `preview/` directory
i = 0
for batch in datagen.flow(x, batch_size=1,
save_to_dir='preview', save_prefix='cat', save_format='jpeg'):
i += 1
if i > num_imgs:
break # otherwise the generator would loop indefinitely
總結
以上是生活随笔為你收集整理的pythonkeras数据增强_Keras数据增强参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习linux第二周作业
- 下一篇: vb.net 如何文件指定打印机打印文件