[英]how to use tensorflow saved_model.load
I am following this official tensorflow tutorial to build a text classification model我正在按照官方 tensorflow 教程构建文本分类 model
I am exporting the trained model as such我正在导出训练有素的 model
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(tf.feature_column.make_parse_example_spec([embedded_text_feature_column]))
export_path = estimator.export_saved_model("./models/sentiment", serving_input_fn)
I was not sure how to pass a sample sentence (eg "it was a great movie") to do prediction when loading.我不确定如何在加载时通过例句(例如“这是一部很棒的电影”)来进行预测。
imported = tf.saved_model.load(b'./models/sentiment/1586848142')
infer = imported.signatures["serving_default"]
This is what you need to load the model这是你需要加载的 model
imported = tf.saved_model.load(export_path)
def predict(x):
example = tf.train.Example()
example.features.feature["sentence"].bytes_list.value.extend([x])
out = imported.signatures["predict"](examples=tf.constant([example.SerializeToString()]))['probabilities']
return out
x = b"I am happy"
predict(x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.