简体   繁体   English

如何部署使用 export_saved_model 保存的 TensorFlow 模型

[英]How to deploy a TensorFlow model that is saved using export_saved_model

I have a.pbtxt file that I have through export_saved_model from inception_v4, however I can't use this saved_model to do prediction.我有一个 .pbtxt 文件,我通过 inception_v4 的 export_saved_model 获得了它,但是我不能使用这个 saved_model 进行预测。 When I try to load the model using tf.contrib.predictor.from_saved_model() I get the following error:当我尝试使用tf.contrib.predictor.from_saved_model()加载模型时,出现以下错误:

OSError: Cannot parse file b'/Users/mehdi/Desktop/serving/saved_model.pbtxt': 1:1 :   
Message type "tensorflow.SavedModel" has no field named "node"..

You can do it using two ways:您可以使用两种方式做到这一点:

  1. By Loading the Saved Model and Predicting using the Loaded Model通过加载保存的模型并使用加载的模型进行预测

    New_Model = tf.keras.models.load_model("saved_model")

    New_Model.summary()

    Prediction = New_Model.predict(...)

    1. Using Tensorflow Serving: Executing the below commands in the Terminal使用 Tensorflow Serving:在终端中执行以下命令

Install the Tensorflow Serving using the Docker Image使用 Docker 镜像安装 Tensorflow 服务

sudo docker pull tensorflow/serving

# Invoke the Tensorflow Model Server
sudo docker run -p 8501:8501 --mount type=bind,source=Path_Of_The_Saved_Model_In_PC,target=/models/saved_model -e MODEL_NAME=saved_model -t tensorflow/serving &

#To get the status of the model
curl http://localhost:8501/v1/models/saved_model

curl -d '{"instances": [1.0, 2.0, 5.0]}' \
    -X POST http://localhost:8501/v1/models/saved_model:predict

If you have an Image as Input and if you want to perform some pre-processing of that image in a Client File, you can do it using the commands mentioned below:如果你有一个图像作为输入,并且你想在客户端文件中对该图像进行一些预处理,你可以使用下面提到的命令来完成:

sudo docker pull tensorflow/serving

sudo docker run -p 8501:8501 --mount type=bind,source=Path_Of_The_Model,target=/models/saved_model -e MODEL_NAME=saved_model -t tensorflow/serving &

python Path/client.py --num_tests=100 --server=localhost:8500

Please refer this link for Code for Client file for TF Serving, this Guide for more info on TF Serving and this Tutorial for End to End Example.请参阅此链接以获取 TF 服务的客户端文件代码、此指南以获取有关 TF 服务的更多信息以及此端到端示例教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM