Keras model.predict()不兼容的尺寸

时间:2020-05-22 18:12:43

标签: python tensorflow keras

我正在尝试使用Keras和TensorFlow进行模型预测。假设使用model.predict()函数时,我给它一个形状为[1,2160,8]的np.array,程序将抛出错误,说明:

ValueError: Input 0 of layer sequential_9 is incompatible with the layer: expected axis -1 of input shape to have value 1 but received input with shape [None, 2160, 8]

另外,我正在馈送的np.array的形状为[1,2160,8],但错误表明它的形状为[None,2160,8]。

这是我的预测代码:

test = np.array([[[1,2,3,4,5,6,7,8]]*2160], np.uint32)

reconstructed_model = keras.models.load_model('saved_model/my_model_cnn')
reconstructed_model.summary()
res = reconstructed_model.predict(test)

model.summary如下:

Model: "sequential_9"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv1d_9 (Conv1D)            (None, 2160, 8)           40        
_________________________________________________________________
flatten_9 (Flatten)          (None, 17280)             0         
_________________________________________________________________
dropout_9 (Dropout)          (None, 17280)             0         
_________________________________________________________________
output (Dense)               (None, 1)                 17281     
=================================================================
Total params: 17,321
Trainable params: 17,321
Non-trainable params: 0
_________________________________________________________________

有人知道如何解决此问题吗?

0 个答案:

没有答案