[英]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
參數放在True
或Flase
上,但它似乎不會影響我從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.