我正在尝试使用斯坦福大学Dogs数据集来练习使用图像增强和创建图像分类器。
我想我的问题可能与我如何在normalize函数中调整图像大小有关。
代码如下:
第一个
错误:
Epoch 1/50
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-a35416ceec02> in <module>
47 train_dataset,
48 epochs = epochs,
---> 49 steps_per_epoch = 1200
50 )
1 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py in tf__train_function(iterator)
13 try:
14 do_return = True
---> 15 retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False
ValueError: in user code:
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1051, in train_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1040, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1030, in run_step **
outputs = model.train_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 889, in train_step
y_pred = self(x, training=True)
File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py", line 264, in assert_input_compatibility
raise ValueError(f'Input {input_index} of layer "{layer_name}" is '
ValueError: Input 0 of layer "sequential_5" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(None, None, 3)
]
我试着在模型中使用tf.layers.resizing(),但是得到了一个关于输入形状的类似错误。
1条答案
按热度按时间huwehgph1#
引发此错误的原因是train_dataset和输入形状之间的形状不匹配,这两个形状分别为(None,None,3)和(224,224,3)。必须首先使用normalize函数调整train数据集的大小,然后创建training_batches。
然后,training_batches应该传递给fit()。
请参考此gist。谢谢!