From 2f48efda049fdc11a702565f50d37f8227e50733 Mon Sep 17 00:00:00 2001 From: jm12138 <2286040843@qq.com> Date: Thu, 29 Dec 2022 10:14:52 +0800 Subject: [PATCH] add gradio app (#2165) --- .../pyramidbox_lite_server/README.md | 10 ++++- .../pyramidbox_lite_server/README_en.md | 8 +++- .../pyramidbox_lite_server/data_feed.py | 1 - .../pyramidbox_lite_server/module.py | 39 +++++++++++++++---- .../pyramidbox_lite_server/processor.py | 3 +- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/modules/image/face_detection/pyramidbox_lite_server/README.md b/modules/image/face_detection/pyramidbox_lite_server/README.md index 47417aa7..4da44a9f 100644 --- a/modules/image/face_detection/pyramidbox_lite_server/README.md +++ b/modules/image/face_detection/pyramidbox_lite_server/README.md @@ -150,6 +150,10 @@ print(r.json()["results"]) ``` +- ### gradio app 支持 + + 从 PaddleHub 2.3.1 开始支持使用链接 http://127.0.0.1:8866/gradio/pyramidbox_lite_server 在浏览器中访问 pyramidbox_lite_server 的 Gradio APP。 + ## 五、更新历史 @@ -169,6 +173,10 @@ 修复无法导出推理模型的问题 +* 1.4.0 + + 添加 Gradio APP 支持 + - ```shell - $ hub install pyramidbox_lite_server==1.3.0 + $ hub install pyramidbox_lite_server==1.4.0 ``` diff --git a/modules/image/face_detection/pyramidbox_lite_server/README_en.md b/modules/image/face_detection/pyramidbox_lite_server/README_en.md index 67fa28b3..8c5cfeb7 100644 --- a/modules/image/face_detection/pyramidbox_lite_server/README_en.md +++ b/modules/image/face_detection/pyramidbox_lite_server/README_en.md @@ -150,6 +150,8 @@ print(r.json()["results"]) ``` +- ### Gradio APP support + Starting with PaddleHub 2.3.1, the Gradio APP for pyramidbox_lite_server is supported to be accessed in the browser using the link http://127.0.0.1:8866/gradio/pyramidbox_lite_server. ## V.Release Note @@ -169,6 +171,10 @@ Fix a bug of save_inference_model +* 1.4.0 + + Add Gradio APP support. + - ```shell - $ hub install pyramidbox_lite_server==1.3.0 + $ hub install pyramidbox_lite_server==1.4.0 ``` diff --git a/modules/image/face_detection/pyramidbox_lite_server/data_feed.py b/modules/image/face_detection/pyramidbox_lite_server/data_feed.py index a2cb2883..b2d51e20 100644 --- a/modules/image/face_detection/pyramidbox_lite_server/data_feed.py +++ b/modules/image/face_detection/pyramidbox_lite_server/data_feed.py @@ -1,4 +1,3 @@ -# coding=utf-8 import os import time from collections import OrderedDict diff --git a/modules/image/face_detection/pyramidbox_lite_server/module.py b/modules/image/face_detection/pyramidbox_lite_server/module.py index 5fe7c7a5..e16ff8d9 100644 --- a/modules/image/face_detection/pyramidbox_lite_server/module.py +++ b/modules/image/face_detection/pyramidbox_lite_server/module.py @@ -1,4 +1,3 @@ -# coding=utf-8 from __future__ import absolute_import from __future__ import division @@ -7,13 +6,12 @@ import ast import os import numpy as np -import paddle from paddle.inference import Config from paddle.inference import create_predictor + from .data_feed import reader from .processor import base64_to_cv2 from .processor import postprocess - from paddlehub.module.module import moduleinfo from paddlehub.module.module import runnable from paddlehub.module.module import serving @@ -24,10 +22,12 @@ from paddlehub.module.module import serving author="baidu-vis", author_email="", summary="PyramidBox-Lite-Server is a high-performance face detection model.", - version="1.3.0") + version="1.4.0") class PyramidBoxLiteServer: + def __init__(self): - self.default_pretrained_model_path = os.path.join(self.directory, "pyramidbox_lite_server_face_detection", "model") + self.default_pretrained_model_path = os.path.join(self.directory, "pyramidbox_lite_server_face_detection", + "model") self._set_config() self.processor = self @@ -35,8 +35,8 @@ class PyramidBoxLiteServer: """ predictor config setting """ - model = self.default_pretrained_model_path+'.pdmodel' - params = self.default_pretrained_model_path+'.pdiparams' + model = self.default_pretrained_model_path + '.pdmodel' + params = self.default_pretrained_model_path + '.pdiparams' cpu_config = Config(model, params) cpu_config.disable_glog_info() cpu_config.disable_gpu() @@ -188,3 +188,28 @@ class PyramidBoxLiteServer: type=ast.literal_eval, default=0.6, help="confidence threshold.") + + def create_gradio_app(self): + import gradio as gr + import tempfile + import os + from PIL import Image + + def inference(image, shrink, confs_threshold): + with tempfile.TemporaryDirectory() as temp_dir: + self.face_detection(paths=[image], + use_gpu=False, + visualization=True, + output_dir=temp_dir, + shrink=shrink, + confs_threshold=confs_threshold) + return Image.open(os.path.join(temp_dir, os.listdir(temp_dir)[0])) + + interface = gr.Interface(inference, [ + gr.inputs.Image(type="filepath"), + gr.Slider(0.0, 1.0, 0.5, step=0.01), + gr.Slider(0.0, 1.0, 0.6, step=0.01) + ], + gr.outputs.Image(type="ndarray"), + title='pyramidbox_lite_server') + return interface diff --git a/modules/image/face_detection/pyramidbox_lite_server/processor.py b/modules/image/face_detection/pyramidbox_lite_server/processor.py index 2045f51c..b46b3013 100644 --- a/modules/image/face_detection/pyramidbox_lite_server/processor.py +++ b/modules/image/face_detection/pyramidbox_lite_server/processor.py @@ -1,12 +1,11 @@ -# coding=utf-8 from __future__ import absolute_import from __future__ import division from __future__ import print_function +import base64 import os import time -import base64 import cv2 import numpy as np from PIL import Image -- GitLab