[英]M1 Max Tensorflow model.fit() InvalidArgumentError
[英]InvalidArgumentError with model.fit in Tensorflow
使用 CNN 進行圖像分類。 當調用model.fit()
時,它開始訓練 model 一段時間,並在執行過程中中斷並返回錯誤消息。
錯誤信息如下
InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: Input size should match (header_size + row_size * abs_height) but they differ by 2
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
[[IteratorGetNext/_4]]
(1) Invalid argument: Input size should match (header_size + row_size * abs_height) but they differ by 2
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_8873]
Function call stack:
train_function -> train_function
更新:我的建議是檢查數據集的元數據。 它幫助解決了我的問題。
您不必指定參數label_mode
。 為了使用SparseCategoricalCrossentropy
作為損失 function 您需要將其設置為int
。 如果您未指定它,則根據文檔將其設置為None
。
您還需要根據從中讀取圖像的目錄結構指定要inferred
的參數labels
。
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
labels="inferred",
label_mode="int",
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
labels="inferred",
label_mode="int",
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
我剛剛在另一個帖子中回答了一個非常相似的問題。 事實上,根本問題可能完全相同。 它包含對至少在我的情況下發生的事情的詳細解釋。 長話短說,我證明是正確的一個可能原因是JPEG 文件損壞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.