【发布时间】:2021-03-17 03:31:03
【问题描述】:
根据Keras Sequential Model .predict()文档,该模型可以使用多种输入形式,包括:
一个 TensorFlow 张量,或一个张量列表(如果模型有多个输入)。
这正是我想要做的,即使用两个张量的“批次”作为 predict() 的输入,并在以下代码中获得两个预测作为输出:
test_batch = (img_tf1, img_tf2) # two Tensors in list
predictions = model.predict(test_batch)
但是我收到以下错误:
ValueError: Layer sequential expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(32, 224, 3) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(32, 224, 3) dtype=float32>]
形状如下:
- 模型输入:
<KerasTensor: shape=(None, 224, 224, 3) dtype=float32 - test_batch:
(<tf.Tensor: shape=(224, 224, 3), dtype=float32>, <tf.Tensor: shape=(224, 224, 3), dtype=float32>)
有谁知道问题出在哪里?我相信我正确使用了 API,正如文档中所指定的那样。我的 TensorFlow 版本是 2.4.0,在 conda 环境中使用 pip 安装。
【问题讨论】:
标签: python tensorflow machine-learning keras deep-learning