[英]Keras ImageDataGenerator returns images with unexpected distortion
我正在試驗 Keras 的ImageDataGenerator()
以便在訓練 CNN 模型之前擴充我的圖像數據集。
我使用的基本生成器對象是:
datagen = ImageDataGenerator(rotation_range = 30,
width_shift_range = 0.2,
height_shift_range = 0.2,
horizontal_flip = True)
然后我生成一些增強數據:
batch_1 = datagen.flow(image_batch, y = labels,
batch_size = len(image_batch),
seed = 173)
當我試圖查看那個batch_1
對象時,我發現了這樣的圖片:
如您所見,有一些我無法解釋的平行彩色線條。 沒有關於ImageDataGenerator()
的在線教程顯示此類失真。 如果輸入這些圖像,CNN 是否得到正確訓練?
我在使用 ImageDataGenerator 時遇到了同樣的問題。 它不是由於 rotation_range 而發生的,它實際上發生在我們使用 width_shift_range 和 height_shift_range 時。 我們可以使用不同的 fill_mode 來處理。 我將 fill_mode 更改為“反映”,因為我的數據集包含葉子。
train_iter = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255,validation_split = 0.2,
preprocessing_function = tf.keras.applications.efficientnet.preprocess_input,
rotation_range = 40,
zoom_range = 0.10,
cval = 0.,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range = 0.2,
horizontal_flip = True,
vertical_flip = True,
fill_mode = 'reflect')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.