5.python请求部署在tensorflow_serving
程序员文章站
2022-06-26 17:07:25
根据训练时的格式调整图片格式pic_path = 'H:\\Nymphaea\\6\\IMG_1727.JPG'img = Image.open(pic_path)img = img.resize((128, 128), Image.ANTIALIAS)img_arr = np.array(img)img_arr = img_arr / 255.0x_test = np.reshape(img_arr, (128, 128, 3))x_predict = x_test[tf.newaxis...
目录
-
根据训练时的格式调整图片格式
pic_path = 'H:\\Nymphaea\\6\\IMG_1727.JPG' img = Image.open(pic_path) img = img.resize((128, 128), Image.ANTIALIAS) img_arr = np.array(img) img_arr = img_arr / 255.0 x_test = np.reshape(img_arr, (128, 128, 3)) x_predict = x_test[tf.newaxis, ...]
-
转换位json格式
import json data = json.dumps({"signature_name": "serving_default", "instances": x_predict.tolist()}) print('Data: {} ... {}'.format(data[:50], data[len(data)-52:]))
-
post数据并接收返回值
headers = {"content-type": "application/json"} json_response = requests.post('http://10.0.68.22:8502/v1/models/googlenet_model:predict', data=data, headers=headers) predictions = json.loads(json_response.text)['predictions']
-
打印最大值
print(np.argmax(predictions[0]))
本文地址:https://blog.csdn.net/qq_34387412/article/details/110453675
上一篇: 以后宝宝可怎么办啊
下一篇: 荣耀50系列真机曝光!网友感叹:颜值惊艳