簡體   English   中英

Keras FlowFromDirectory 中的隨機播放參數似乎不起作用

[英]Shuffle parameter in Keras FlowFromDirectory doesn't seem to work

我正在研究一個混合數據類型 keras 深度學習項目。 我使用以下教程: https://heartbeat.fritz.ai/building-a-mixed-data-neural-network-in-keras-to-predict-accident-locations-d51a63b738cf

正如那里所解釋的,我通過 flowfromdirectory 加載我的圖像,我需要獲取文件名及其確切順序,以便我可以將它與與之關聯的正確元數據匹配。

我查看了 Keras 關於 function 的文檔: https://keras.io/api/preprocessing/image/#flowfromdirectory-method

雖然我將shuffle參數放在TrueFlase上,但它似乎不會影響我從ImageDataGenerator獲得的圖像的順序,並且它始終顯示字母數字順序:

使用suffle=True加載圖像:

在此處輸入圖像描述

使用suffle=False加載圖像:

在此處輸入圖像描述

我怎樣才能確定我的 train_flow 被有效地改組了?
如何檢索文件在 train_flow 中加載的確切順序?

我對 Keras 很陌生,這可能是一個愚蠢的問題,或者是我的愚蠢錯誤,請友好地回答:) 感謝您的幫助!

generator.filenames 中的文件名列表確實是 static。 然而,每個生成的批次上的圖像都被打亂了。

from tensorflow.keras.preprocessing.image import ImageDataGenerator

# directory contains two images. one back, one white
train_dir = 'C:/dev/test'

data_gen = ImageDataGenerator(rescale=1. / 255)

generator = data_gen.flow_from_directory(train_dir, target_size=(200, 200), 
batch_size=2, class_mode='categorical', shuffle=True)

idx = 0
for batch in generator:
    print(f'batch# {idx}')
    # first pixel of images
    print(batch[0][0][0][0])
    print(batch[0][1][0][0])

    idx += 1
    if idx == 5: exit()

Found 2 images belonging to 1 classes.
batch# 0
[0. 0. 0.]
[1. 1. 1.]
batch# 1
[1. 1. 1.]
[0. 0. 0.]
batch# 2
[1. 1. 1.]
[0. 0. 0.]
batch# 3
[1. 1. 1.]
[0. 0. 0.]
batch# 4
[0. 0. 0.]
[1. 1. 1.]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM