使用CNN进行图像分类。当model.fit()
被调用时,它开始训练模型了一会儿,在执行过程中被中断,并返回一个错误消息。
错误信息如下
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
用作损失函数,您需要将其设置为int
。如果未指定,则根据文档设置None
为。
您还需要指定参数labels
要在inferred
基于目录的,你从中读取图像的结构。
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句