[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:
Wang Xinyu
2022-12-26 21:09:08 +08:00
committed by GitHub
parent ec67f8ee6d
commit 22d91a73c6
18 changed files with 707 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# coding:utf-8
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import contextlib
import base64
import numpy as np
import cv2
@contextlib.contextmanager
def lock_predictor(lock):
lock.acquire()
try:
yield
finally:
lock.release()
def cv2_to_base64(image):
data = cv2.imencode('.jpg', image)[1]
return base64.b64encode(data.tobytes()).decode('utf8')
def base64_to_cv2(b64str):
data = base64.b64decode(b64str.encode('utf8'))
data = np.fromstring(data, np.uint8)
data = cv2.imdecode(data, cv2.IMREAD_COLOR)
return data