http接口说明:
- 查看TensorFlow-Serving状态:
curl http://localhost:8501/v1/models/${model_name}
- 查看TensorFlow-Serviing模型:
curl http://localhost:8501/v1/models/${model_name}/metadata
- 使用Http请求进行模型预测:
curl -d '{"instances": [1,2,3,4,5]}' -X POST http://localhost:8501/v1/models/${model_name}:predict
其中instances的value为模型输入Tensor的字符串形式,矩阵维度需要和Tensor对应。
- 查看模型情况
saved_model_cli show --dir='./${model_path}/1' --all
python 调用restful接口:
def textclassification_cls():
input_data_json = json.dumps({
"instances": [{"user_sex":[1],
"patient_sex":[1],
"city_id":[5],
"user_age":[4],
"patient_age":[4],
"click":[0.002930],
"category_array":[1156,1156,1605,984],
"dep_ids":[112]+[0]*39,
"user_tag_zydjysnr90r": [31,3,9]+[0]*9,
"user_tag_public_department_click_30d": [7008, 10801,7009]+[0]*900,
"user_tag_disease_search_90d":[2799]+[0]*5
},{"user_sex":[1],
"patient_sex":[1],
"city_id":[5],
"user_age":[4],
"patient_age":[4],
"click":[0.002930],
"category_array":[1156,1156,1605,984],
"dep_ids":[112]+[0]*39,
"user_tag_zydjysnr90r": [31,3,9]+[0]*9,
"user_tag_public_department_click_30d": [7008, 10801,7009]+[0]*900,
"user_tag_disease_search_90d":[2799]+[0]*5
}]
})
SERVER_URL = 'http://10.1.2.106:8501/v1/models/deep-model:predict'
# SERVER_URL = 'http://deepfm.api.91160.com/v1/models/deep-model:predict'
import time
times = time.time()
response = requests.post(SERVER_URL, data=input_data_json)
res = json.loads(response.text)
timee = time.time()
print("耗时:",timee-times)
return str(res)
if __name__ == "__main__":
print(textclassification_cls())
存在的问题
- 多维数组维度可以任意
- padding 的0加不加结果一样