简单粗暴的tensorflow-TensorFlow Serving

# TensorFlow Serving部署
# 服务器端,安装TensorFlow Serving
tensorflow_model_server \
    --rest_api_port=端口号(如8501) \
    --model_name=模型名 \
    --model_base_path="SavedModel格式模型的文件夹绝对地址(不含版本号)"

#客户端,发送请求
import json
import numpy as np
import requests
from zh.model.utils import MNISTLoader


data_loader = MNISTLoader()
data = json.dumps({
    "instances": data_loader.test_data[0:3].tolist()
    })
headers = {"content-type": "application/json"}
json_response = requests.post(
    'http://localhost:8501/v1/models/MLP:predict',
    data=data, headers=headers)
predictions = np.array(json.loads(json_response.text)['predictions'])
print(np.argmax(predictions, axis=-1))
print(data_loader.test_label[0:10]) 
posted @ 2022-02-18 11:20  wuyuan2011woaini  阅读(82)  评论(0编辑  收藏  举报