【发布时间】:2021-08-03 17:07:17
【问题描述】:
我在使用自定义训练模型进行预测时遇到问题。
输入128维向量,输出两个值。
到目前为止,我的模型如下所示:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense_12 (Dense) (None, 128) 16512
_________________________________________________________________
dense_13 (Dense) (None, 2) 258
=================================================================
Total params: 16,770
Trainable params: 16,770
Non-trainable params: 0
因此我尝试输入数据来进行预测,(出于示例目的,它只是一个 np.ones 数组)
my_model = tf.keras.models.load_model('my_saved_model.h5')
probability_model = tf.keras.Sequential([my_model, tf.keras.layers.Softmax()])
simple_data = np.ones((128))
predictions = probability_model.predict(simple_data)
print(predictions)
并输出关于 simple_data 形状为 (32, 1) 的错误:
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 128 but received input with shape (32, 1)
我不知道为什么。
提前致谢
【问题讨论】:
标签: python numpy tensorflow