拉去tensorflow srving 镜像
docker pull tensorflow/serving:1.12.0
代码里新增tensorflow 配置代码
# 要指出输入,输出张量
#指定保存路径
# serving_save
signature = tf.saved_model.signature_def_utils.predict_signature_def(
inputs={'input_param': model.inputs_placeholder}, outputs={'type': model.the_outputs})
builder = tf.saved_model.builder.SavedModelBuilder('../serving_save/001')
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tf.saved_model.tag_constants.SERVING],
signature_def_map={
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature
})
builder.save()
启动服务
docker run -p 8501:8501 --mount type=bind,source=F:avaintecaad_by_me_newserving_save,target=/models/aad_serve -e MODEL_NAME=aad_serve -t tensorflow/serving &
访问服务
que = [1, 2, 3, 44, 5, 6, 7, 8] + [0] * 348
input = [que]
print(input)
url = 'http://localhost:8501/v1/models/aad_serve:predict'
headers = {
"Host": "anticvarium.ru",
"Connection": "keep-alive",
"Content-Length": "14",
"Origin": "http://anticvarium.ru",
"X-CSRF-TOKEN": "u1InfvhE23slcmReIJlgvI7IGzb3xQEvXHQbP3Bc",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Content-Type": "application/json;charset=UTF-8",
"Accept": "application/json, text/plain, */*",
"X-Requested-With": "XMLHttpRequest",
"Referer": "http://anticvarium.ru/auction/show/66",
"Accept-Language": "zh",
"Cookie": "_ga=GA1.2.819821684.1533003173; _gid=GA1.2.258681840.1533003173; _ym_uid=1533003182951117996; _ym_d=1533003182; _ym_isad=2; _ym_visorc_35976415=w; tmr_detect=0%7C1533004777867; laravel_session=eyJpdiI6InZNSTlWSlYyUW1BaitUWTNBSjJKckE9PSIsInZhbHVlIjoibWprTDFxeTZZc0lOS2VTcmxIdzZJSkwwTVFXOHphN2FwTysxbXNHSDkybXE0VUZYakpTUlZ5Ykh6U2pFTTVJTWdWUHBUaVJwVGl1Q3RlTjdRQUhKNEE9PSIsIm1hYyI6IjQ5NmIwMGYxNDllZDFiNTY2ZmFjYWY5NjEyOTQ4MTZjYzQzNmFiY2EyMzFiOTY1Mzg3ODUyZTllN2U0MTQwYTEifQ%3D%3D",
}
response = requests.post(url, headers=headers, json={"instances": input})
print(response.text)
print('ok')
预测结果
遗留问题
tensorflow serving 保存的时侯,只保存了,模型graphy相关的操作。数据预处理操作,不在serving服务中。
所以数据的预处理等,需要重新做。
可不可以再服务中,直接包含数据预处理部分???
参考链接
https://www.cnblogs.com/xing901022/p/10216933.html
https://blog.csdn.net/weixin_34343000/article/details/88118667
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:tensorflow serving 模型部署 - Python技术站