【发布时间】:2019-12-06 23:21:16
【问题描述】:
到目前为止,我使用tf.contrib.predictor.from_saved_model 加载SavedModel(tf.estimator 模型类)。但是,很遗憾,此功能已在 TensorFlow v2 中删除。到目前为止,在 TensorFlow v1 中,我的编码如下:
predict_fn = predictor.from_saved_model(model_dir + '/' + model, signature_def_key='predict')
prediction_feed_dict = dict()
for key in predict_fn._feed_tensors.keys():
#forec_data is a DataFrame holding the data to be fed in
for index in forec_data.index:
prediction_feed_dict[key] = [ [ forec_data.loc[index][key] ] ]
prediction_complete = predict_fn(prediction_feed_dict)
使用tf.saved_model.load,我在 TensorFlow v2 中尝试以下操作失败:
model = tf.saved_model.load(model_dir + '/' + latest_model)
model_fn = model.signatures['predict']
prediction_feed_dict = dict()
for key in model_fn._feed_tensors.keys(): #<-- no replacement for _feed_tensors.keys() found
#forec_data is a DataFrame holding the data to be fed in
for index in forec_data.index:
prediction_feed_dict[key] = [ [ forec_data.loc[index][key] ] ]
prediction_complete = model_fn(prediction_feed_dict) #<-- no idea if this is anyhow close to correct
所以我的问题是(都在 TensorFlow v2 的上下文中):
- 如何替换
_feed_tensors.keys()? - 如何使用加载了
tf.saved_model.load的tf.estimator模型以简单的方式进行推理
非常感谢,感谢任何帮助。
注意:此问题与 here 发布的问题不是重复的,因为那里提供的答案都依赖于 TensorFlow v1 中已在 TensorFlow v2 中删除的功能。
编辑: postet here 的问题似乎问的基本相同,但直到现在(2020-01-22)也没有答案。
【问题讨论】:
标签: python tensorflow tensorflow-serving tensorflow2.0 tensorflow-estimator