pythonkeras数据增强_Keras数据增强参数
我在Keras中讀過一些關(guān)于數(shù)據(jù)擴(kuò)充的資料,但對我來說還是有點(diǎn)模糊。在數(shù)據(jù)擴(kuò)充步驟中,是否有任何參數(shù)來控制從每個輸入圖像創(chuàng)建的圖像的數(shù)量?在this example中,我看不到任何控制從每個圖像創(chuàng)建的圖像數(shù)量的參數(shù)。在
例如,在下面的代碼中,我可以使用一個參數(shù)(num_imgs)來控制從每個輸入圖像創(chuàng)建并存儲在名為preview的文件夾中的圖像數(shù)量;但是在實(shí)時數(shù)據(jù)擴(kuò)充中,沒有任何參數(shù)用于此目的。在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
總結(jié)
以上是生活随笔為你收集整理的pythonkeras数据增强_Keras数据增强参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习linux第二周作业
- 下一篇: python散点图如何设置外边框_如何绘