【发布时间】:2020-02-20 15:13:40
【问题描述】:
这是我的模型:
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(40, 40, 3)),
tf.keras.layers.Dense(150, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10)
])
我的输入张量称为 image_batch 。当我运行np.shape(image_batch[0]) 时,结果是TensorShape([40, 40, 3])。这是预期的行为,因为每个训练示例都是 40x40x3 的 rgb 图像)。
但是,当运行命令predictions = model(image_batch[0]).numpy() 以获取模型的预测时,我得到了错误:
WARNING:tensorflow:Model was constructed with shape Tensor("flatten_1_input:0", shape=(None, 40, 40, 3), dtype=float32) for input (None, 40, 40, 3), but it was re-called on a Tensor with incompatible shape (40, 40, 3).
所以我的问题是为什么 keras 模型需要一个具有额外“无”维度的形状,我如何将它提供给模型?
【问题讨论】:
标签: python tensorflow keras tensor