简体   繁体   English

如何将新模型推送到 tensorflow-serving?

[英]How to push a new model to tensorflow-serving?

I need a way to use Python 3 to push newly trained models to a deployed container running tensorflow-serving .我需要一种使用Python 3将新训练的模型推送到运行tensorflow-serving的已部署容器的方法。

Found the tfx package ( https://www.tensorflow.org/tfx/guide/pusher ) but it only works with python 2.7 .找到了 tfx 包 ( https://www.tensorflow.org/tfx/guide/pusher ) 但它只适用于python 2.7

Also found this question that points out that this functionality exists:https://stackoverflow.com/questions/50052187/how-to-add-a-new-model-in-tensorflow-serving还发现这个问题指出这个功能存在:https://stackoverflow.com/questions/50052187/how-to-add-a-new-model-in-tensorflow-serving

But I'm still lacking a good guide on how to deploy a new model using Python 3 .但我仍然缺乏关于如何使用Python 3部署新模型的良好指南。

I have created a Model and have saved it in the path, "/usr/local/google/home/abc/Jupyter_Notebooks/export".我创建了一个模型并将其保存在路径“/usr/local/google/home/abc/Jupyter_Notebooks/export”中。

Then, I have committed it to the Tensorflow Serving Docker Container and inferenced that Model and got the results.然后,我将其提交给 Tensorflow Serving Docker Container 并推断该模型并获得结果。

Commands to be run in Command Prompt, for achieving what is explained above is shown below:要在命令提示符中运行的命令,以实现上面解释的内容,如下所示:

sudo docker run -d --name sb tensorflow/serving

sudo docker cp /usr/local/google/home/abc/Jupyter_Notebooks/export sb:/models/export

sudo docker commit --change "ENV MODEL_NAME export" sb rak_iris_container

sudo docker kill sb

sudo docker pull tensorflow/serving

sudo docker run -p 8501:8501 --mount type=bind,source=/usr/local/google/home/abc/Jupyter_Notebooks/export,target=/models/export -e MODEL_NAME=export -t tensorflow/serving &

saved_model_cli show --dir /usr/local/google/home/abc/Jupyter_Notebooks/export/1554294699 --all

curl -d '{"examples":[{"SepalLength":[5.1],"SepalWidth":[3.3],"PetalLength":[1.7],"PetalWidth":[0.5]}]}' \
  -X POST http://localhost:8501/v1/models/export:classify

Output of above inference is上述推论的输出是

{
    "results": [[["0", 0.998091], ["1", 0.00190929], ["2", 1.46236e-08]]
    ]
}

Model is saved using the code mentioned below:使用下面提到的代码保存模型:

feature_spec = tf.feature_column.make_parse_example_spec(my_feature_columns)
serving_input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
export_dir = classifier.export_savedmodel('export', serving_input_receiver_fn)
print('Exported to {}'.format(export_dir))

Output of above command is:上述命令的输出是:

Exported to b'/usr/local/google/home/abc/Jupyter_Notebooks/export/1554980806'导出到 b'/usr/local/google/home/abc/Jupyter_Notebooks/export/1554980806'

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

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