mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
[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:
38
examples/vision/detection/yolov5/python/serving/server.py
Normal file
38
examples/vision/detection/yolov5/python/serving/server.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import fastdeploy as fd
|
||||
from fastdeploy.serving.server import SimpleServer
|
||||
import os
|
||||
import logging
|
||||
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
# Configurations
|
||||
model_dir = 'yolov5s_infer'
|
||||
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")
|
||||
|
||||
# Setup runtime option to select hardware, backend, etc.
|
||||
option = fd.RuntimeOption()
|
||||
if device.lower() == 'gpu':
|
||||
option.use_gpu()
|
||||
if use_trt:
|
||||
option.use_trt_backend()
|
||||
option.set_trt_input_shape("images", [1, 3, 640, 640])
|
||||
option.set_trt_cache_file('yolov5s.trt')
|
||||
|
||||
# Create model instance
|
||||
model_instance = fd.vision.detection.YOLOv5(
|
||||
model_file,
|
||||
params_file,
|
||||
runtime_option=option,
|
||||
model_format=fd.ModelFormat.PADDLE)
|
||||
|
||||
# Create server, setup REST API
|
||||
app = SimpleServer()
|
||||
app.register(
|
||||
task_name="fd/yolov5s",
|
||||
model_handler=fd.serving.handler.VisionModelHandler,
|
||||
predictor=model_instance)
|
Reference in New Issue
Block a user