如何使用"模型".预测目标何时是张量流的一个输入?



我注意到https://www.tensorflow.org/guide/keras/train_and_evaluate#automatically_setting_apart_a_validation_holdout_set中的LogisticEndpoint层。文档构建如下的模型:

import numpy as np
inputs = keras.Input(shape=(3,), name="inputs")
targets = keras.Input(shape=(10,), name="targets")
logits = keras.layers.Dense(10)(inputs)
predictions = LogisticEndpoint(name="predictions")(logits, targets)
model = keras.Model(inputs=[inputs, targets], outputs=predictions)
model.compile(optimizer="adam")  # No loss argument!
data = {
"inputs": np.random.random((3, 3)),
"targets": np.random.random((3, 10)),
}
model.fit(data)

我的问题是如何在推理时使用这个模型,因为当我们使用model.predict时我们不知道目标

<LogisticEndpoint"实际上是一个层。它接受>预测作为输入,可以计算add_loss()跟踪的损耗,计算add_metric()跟踪的精度标量。

目标,如果我没有错的话,实际上是地面真实数据。当您进行推理(测试阶段,既不是训练也不是验证)时,您不需要基础真值数据。只需将输入传递给模型,然后将输出作为预测。

对多输入进行预测:

首先,将多输入转换成一个数组(可能是一个大数组)。

然后确保数组的形状(或者确切地说,张量)与输入层的大小匹配。

我在TF2中使用了一部分多输入代码。

...
for view_id in range(1,9):
...
img = self.transform(img).float()
pose_2d = self.transform(pose_2d).float()
img_con.append(img)
pose_2d_con.append(pose_2d)
# then make the img_con and pose_2d_con two tensor.

相关内容

最新更新