[Serving] Simple serving YOLOv5 and PP-OCRv3 example, add uvicorn to fastdeploy tools (#986)

* ppocrv3 simple serving

* add uvicorn to fd tools

* update ppdet simple serving readme

* yolov5 simple serving

* not import simple serving by default

* remove config from envs

* update comment
This commit is contained in:
Wang Xinyu
2022-12-28 10:03:42 +08:00
committed by GitHub
parent 0ead9d27c2
commit aea454a856
18 changed files with 364 additions and 42 deletions

View File

@@ -17,16 +17,9 @@ cd FastDeploy/examples/vision/detection/paddledetection/python/serving
wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
tar xvf ppyoloe_crn_l_300e_coco.tgz
# 安装uvicorn
pip install uvicorn
# 启动服务可选择是否使用GPU和TensorRT可根据uvicorn --help配置IP、端口号等
# CPU
MODEL_DIR=ppyoloe_crn_l_300e_coco DEVICE=cpu uvicorn server:app
# GPU
MODEL_DIR=ppyoloe_crn_l_300e_coco DEVICE=gpu uvicorn server:app
# GPU上使用TensorRT 注意TensorRT推理第一次运行有序列化模型的操作有一定耗时需要耐心等待
MODEL_DIR=ppyoloe_crn_l_300e_coco DEVICE=gpu USE_TRT=true uvicorn server:app
# 启动服务可修改server.py中的配置项来指定硬件、后端等
# 可通过--host、--port指定IP和端口号
fastdeploy simple_serving --app server:app
```
客户端:

View File

@@ -17,17 +17,9 @@ cd FastDeploy/examples/vision/detection/paddledetection/python/serving
wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
tar xvf ppyoloe_crn_l_300e_coco.tgz
# Install uvicorn
pip install uvicorn
# Launch server, it's configurable to use GPU and TensorRT,
# and run 'uvicorn --help' to check how to specify IP and port, etc.
# CPU
MODEL_DIR=ppyoloe_crn_l_300e_coco DEVICE=cpu uvicorn server:app
# GPU
MODEL_DIR=ppyoloe_crn_l_300e_coco DEVICE=gpu uvicorn server:app
# GPU and TensorRT
MODEL_DIR=ppyoloe_crn_l_300e_coco DEVICE=gpu USE_TRT=true uvicorn server:app
# Launch server, change the configurations in server.py to select hardware, backend, etc.
# and use --host, --port to specify IP and port
fastdeploy simple_serving --app server:app
```
Client:

View File

@@ -1,20 +1,15 @@
import requests
import json
import cv2
import base64
import fastdeploy as fd
from fastdeploy.serving.utils import cv2_to_base64
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": {}
}
data = {"data": {"image": cv2_to_base64(im)}, "parameters": {}}
resp = requests.post(url=url, headers=headers, data=json.dumps(data))
if resp.status_code == 200:

View File

@@ -1,18 +1,16 @@
import fastdeploy as fd
from fastdeploy.serving.server import SimpleServer
import os
import logging
logging.getLogger().setLevel(logging.INFO)
# Get arguments from envrionment variables
model_dir = os.environ.get('MODEL_DIR')
device = os.environ.get('DEVICE', 'cpu')
use_trt = os.environ.get('USE_TRT', False)
# Prepare model, download from hub or use local dir
if model_dir is None:
model_dir = fd.download_model(name='ppyoloe_crn_l_300e_coco')
# Configurations
model_dir = 'ppyoloe_crn_l_300e_coco'
device = 'cpu'
use_trt = False
# Prepare model
model_file = os.path.join(model_dir, "model.pdmodel")
params_file = os.path.join(model_dir, "model.pdiparams")
config_file = os.path.join(model_dir, "infer_cfg.yml")
@@ -33,7 +31,7 @@ model_instance = fd.vision.detection.PPYOLOE(
runtime_option=option)
# Create server, setup REST API
app = fd.serving.SimpleServer()
app = SimpleServer()
app.register(
task_name="fd/ppyoloe",
model_handler=fd.serving.handler.VisionModelHandler,