【发布时间】:2020-03-02 19:41:08
【问题描述】:
为什么模型预测工作但模型(数据)在 tf 2.0 中对于以下代码失败?
from tensorflow.keras import layers,Input
import tensorflow as tf
input_layer = Input(1)
d1 = layers.Dense(64, activation='relu')(input_layer)
d2 = layers.Dense(3, activation='relu')(d1)
model = tf.keras.Model(inputs=[input_layer], outputs=d2)
data = [[1.0]]
print(model.predict(data)) # Works
print(model(data)) # fails with tensorflow.python.framework.errors_impl.InvalidArgumentError: In[0] is not a matrix. Instead it has shape [] [Op:MatMul]
【问题讨论】:
标签: python tensorflow tensorflow2.0 tf.keras