mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Serving] Add a simple Python serving (#962)
* init simple serving * simple serving is working * ppyoloe demo * Update README_CN.md * update readme * complete vision result to json
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import requests
|
||||
import json
|
||||
import cv2
|
||||
import base64
|
||||
import fastdeploy as fd
|
||||
|
||||
if __name__ == '__main__':
|
||||
url = "http://127.0.0.1:8000/fd/ppyoloe"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
im = cv2.imread("000000014439.jpg")
|
||||
data = {
|
||||
"data": {
|
||||
"image": fd.serving.utils.cv2_to_base64(im)
|
||||
},
|
||||
"parameters": {}
|
||||
}
|
||||
|
||||
resp = requests.post(url=url, headers=headers, data=json.dumps(data))
|
||||
if resp.status_code == 200:
|
||||
r_json = json.loads(resp.json()["result"])
|
||||
det_result = fd.vision.utils.json_to_detection(r_json)
|
||||
vis_im = fd.vision.vis_detection(im, det_result, score_threshold=0.5)
|
||||
cv2.imwrite("visualized_result.jpg", vis_im)
|
||||
print("Visualized result save in ./visualized_result.jpg")
|
||||
else:
|
||||
print("Error code:", resp.status_code)
|
||||
print(resp.text)
|
Reference in New Issue
Block a user