改变TensorsPec TensorFlow的形状
我目前正在尝试通过转移学习实现VGG16模型,并且在尝试评估该模型时遇到了一个问题。
这就是我所说的:
initial_epochs = 10
loss0, accuracy0 = model.evaluate(validation_dataset)
这就是验证_dataset的样子:
<PrefetchDataset element_spec=(TensorSpec(shape=(None, 3, 96, 96), dtype=tf.uint8, name=None), TensorSpec(shape=(None, 4), dtype=tf.int32, name=None))>
这是我的错误消息:
ValueError Traceback (most recent call last)
<ipython-input-29-c7fea149280c> in <module>()
1 initial_epochs = 10
----> 2 loss0, accuracy0 = model.evaluate(validation_dataset)
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
1145 except Exception as e: # pylint:disable=broad-except
1146 if hasattr(e, "ag_error_metadata"):
-> 1147 raise e.ag_error_metadata.to_exception(e)
1148 else:
1149 raise
ValueError: in user code:
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1525, in test_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1514, 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 1507, in run_step **
outputs = model.test_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1471, in test_step
y_pred = self(x, training=False)
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 "model" is incompatible with the layer: expected shape=(None, 96, 96, 3), found shape=(None, 3, 96, 96)
我尝试将模型输入形状放置为(3,96,96)而不是(96,96,3),但这不是工作... 谁能帮我吗?
I am currently trying to implement a VGG16 model via transfer learning and I'm coming across a problem when trying to evaluate the model.
this is how I call it:
initial_epochs = 10
loss0, accuracy0 = model.evaluate(validation_dataset)
and this is what validation_dataset looks like:
<PrefetchDataset element_spec=(TensorSpec(shape=(None, 3, 96, 96), dtype=tf.uint8, name=None), TensorSpec(shape=(None, 4), dtype=tf.int32, name=None))>
And this is my error message:
ValueError Traceback (most recent call last)
<ipython-input-29-c7fea149280c> in <module>()
1 initial_epochs = 10
----> 2 loss0, accuracy0 = model.evaluate(validation_dataset)
1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py in autograph_handler(*args, **kwargs)
1145 except Exception as e: # pylint:disable=broad-except
1146 if hasattr(e, "ag_error_metadata"):
-> 1147 raise e.ag_error_metadata.to_exception(e)
1148 else:
1149 raise
ValueError: in user code:
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1525, in test_function *
return step_function(self, iterator)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1514, 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 1507, in run_step **
outputs = model.test_step(data)
File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1471, in test_step
y_pred = self(x, training=False)
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 "model" is incompatible with the layer: expected shape=(None, 96, 96, 3), found shape=(None, 3, 96, 96)
I tried putting the model input shape as (3, 96, 96) rather than (96, 96, 3) but that doesn't work...
Can anyone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
validation_dataset.map
和tf.transpose
:Try using
validation_dataset.map
andtf.transpose
: