到目前为止,我正在使用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)
Run Code Online (Sandbox Code Playgroud)
使用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 …Run Code Online (Sandbox Code Playgroud) python tensorflow tensorflow-serving tensorflow-estimator tensorflow2.0