【发布时间】:2020-12-01 10:23:34
【问题描述】:
我的目标是加载一次保存的模型,然后在不同的图像上多次使用它进行推理,以节省每次预测之间的时间。就我而言,加载模型后,第一个预测很好。但是,如果我再次尝试使用该模型,则结果为空。有没有办法多次使用加载的模型进行推理,还是我做错了什么?
我正在使用经过训练的 YoloV4-tiny 模型,该模型已使用 this repository 从 .wheights 文件转换为 .pb 文件。我使用的 tensorflow 版本是 tf-nightly 2.5.0。
代码示例:
saved_model_loaded = tf.saved_model.load(model_weights, tags=[tag_constants.SERVING])
infer = saved_model_loaded.signatures['serving_default']
batch_data = tf.constant(image_data)
prediction_bbox = infer(batch_data)
print('First prediction: ')
print(prediction_bbox)
prediction_bbox = infer(batch_data)
print('Second prediction: ')
print(prediction_bbox)
输出:
First prediction:
{'tf.concat_12': <tf.Tensor: shape=(1, 14, 56), dtype=float32, numpy=
array([[[3.04199923e-02, 4.36968982e-01, 1.12345181e-01, 4.82889146e-01,
7.35657290e-04, 7.31759297e-04, 8.13401653e-04, 7.43044075e-06,
1.19315519e-03, 1.88542936e-06, 2.82156630e-03, 1.12371512e-04,
[...]
2.79035070e-04, 6.39518723e-04, 1.51291722e-04, 7.65962759e-04]]],
dtype=float32)>}
Second prediction:
{'tf.concat_12': <tf.Tensor: shape=(1, 0, 56), dtype=float32, numpy=array([], shape=(1, 0, 56),dtype=float32)>}
【问题讨论】:
标签: python tensorflow