Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
30715e7b
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
30715e7b
编写于
7月 16, 2020
作者:
D
dyning
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
det rec single
上级
d8978e9c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
90 addition
and
22 deletion
+90
-22
python/examples/ocr/ocr_debugger_server.py
python/examples/ocr/ocr_debugger_server.py
+2
-2
python/examples/ocr/ocr_web_client.py
python/examples/ocr/ocr_web_client.py
+1
-5
python/examples/ocr/rec_debugger_server.py
python/examples/ocr/rec_debugger_server.py
+72
-0
tools/serving_build.sh
tools/serving_build.sh
+15
-15
未找到文件。
python/examples/ocr/ocr_debugger_server.py
浏览文件 @
30715e7b
...
@@ -30,7 +30,7 @@ import base64
...
@@ -30,7 +30,7 @@ import base64
class
OCRService
(
WebService
):
class
OCRService
(
WebService
):
def
init_det_debugger
(
self
,
det_
port
,
det_
model_config
):
def
init_det_debugger
(
self
,
det_model_config
):
self
.
det_preprocess
=
Sequential
([
self
.
det_preprocess
=
Sequential
([
ResizeByFactor
(
32
,
960
),
Div
(
255
),
ResizeByFactor
(
32
,
960
),
Div
(
255
),
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
]),
Transpose
(
Normalize
([
0.485
,
0.456
,
0.406
],
[
0.229
,
0.224
,
0.225
]),
Transpose
(
...
@@ -98,6 +98,6 @@ class OCRService(WebService):
...
@@ -98,6 +98,6 @@ class OCRService(WebService):
ocr_service
=
OCRService
(
name
=
"ocr"
)
ocr_service
=
OCRService
(
name
=
"ocr"
)
ocr_service
.
load_model_config
(
"ocr_rec_model"
)
ocr_service
.
load_model_config
(
"ocr_rec_model"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
)
ocr_service
.
init_det_debugger
(
det_
port
=
9293
,
det_
model_config
=
"ocr_det_model"
)
ocr_service
.
init_det_debugger
(
det_model_config
=
"ocr_det_model"
)
ocr_service
.
run_debugger_service
(
gpu
=
True
)
ocr_service
.
run_debugger_service
(
gpu
=
True
)
ocr_service
.
run_web_service
()
ocr_service
.
run_web_service
()
python/examples/ocr/ocr_web_client.py
浏览文件 @
30715e7b
...
@@ -29,13 +29,9 @@ def cv2_to_base64(image):
...
@@ -29,13 +29,9 @@ def cv2_to_base64(image):
headers
=
{
"Content-type"
:
"application/json"
}
headers
=
{
"Content-type"
:
"application/json"
}
url
=
"http://127.0.0.1:9292/ocr/prediction"
url
=
"http://127.0.0.1:9292/ocr/prediction"
test_img_dir
=
"
./imgs
"
test_img_dir
=
"
test_imgs/rctw_samples/
"
for
img_file
in
os
.
listdir
(
test_img_dir
):
for
img_file
in
os
.
listdir
(
test_img_dir
):
image_data
=
cv2
.
imread
(
os
.
path
.
join
(
test_img_dir
,
img_file
))
if
image_data
is
None
:
print
(
"invalid image: "
,
os
.
path
.
join
(
test_img_dir
,
img_file
))
continue
with
open
(
os
.
path
.
join
(
test_img_dir
,
img_file
),
'rb'
)
as
file
:
with
open
(
os
.
path
.
join
(
test_img_dir
,
img_file
),
'rb'
)
as
file
:
image_data1
=
file
.
read
()
image_data1
=
file
.
read
()
image
=
cv2_to_base64
(
image_data1
)
image
=
cv2_to_base64
(
image_data1
)
...
...
python/examples/ocr/rec_debugger_server.py
0 → 100644
浏览文件 @
30715e7b
# Copyright (c) 2020 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.
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
OCRReader
import
cv2
import
sys
import
numpy
as
np
import
os
from
paddle_serving_client
import
Client
from
paddle_serving_app.reader
import
Sequential
,
URL2Image
,
ResizeByFactor
from
paddle_serving_app.reader
import
Div
,
Normalize
,
Transpose
from
paddle_serving_app.reader
import
DBPostProcess
,
FilterBoxes
,
GetRotateCropImage
,
SortedBoxes
from
paddle_serving_server_gpu.web_service
import
WebService
import
time
import
re
import
base64
class
OCRService
(
WebService
):
def
init_rec
(
self
):
self
.
ocr_reader
=
OCRReader
()
def
preprocess
(
self
,
feed
=
[],
fetch
=
[]):
img_list
=
[]
for
feed_data
in
feed
:
data
=
base64
.
b64decode
(
feed_data
[
"image"
].
encode
(
'utf8'
))
data
=
np
.
fromstring
(
data
,
np
.
uint8
)
im
=
cv2
.
imdecode
(
data
,
cv2
.
IMREAD_COLOR
)
img_list
.
append
(
im
)
max_wh_ratio
=
0
for
i
,
boximg
in
enumerate
(
img_list
):
h
,
w
=
boximg
.
shape
[
0
:
2
]
wh_ratio
=
w
*
1.0
/
h
max_wh_ratio
=
max
(
max_wh_ratio
,
wh_ratio
)
_
,
w
,
h
=
self
.
ocr_reader
.
resize_norm_img
(
img_list
[
0
],
max_wh_ratio
).
shape
imgs
=
np
.
zeros
((
len
(
img_list
),
3
,
w
,
h
)).
astype
(
'float32'
)
for
i
,
img
in
enumerate
(
img_list
):
norm_img
=
self
.
ocr_reader
.
resize_norm_img
(
img
,
max_wh_ratio
)
imgs
[
i
]
=
norm_img
feed
=
{
"image"
:
imgs
.
copy
()}
fetch
=
[
"ctc_greedy_decoder_0.tmp_0"
,
"softmax_0.tmp_0"
]
return
feed
,
fetch
def
postprocess
(
self
,
feed
=
{},
fetch
=
[],
fetch_map
=
None
):
rec_res
=
self
.
ocr_reader
.
postprocess
(
fetch_map
,
with_score
=
True
)
res_lst
=
[]
for
res
in
rec_res
:
res_lst
.
append
(
res
[
0
])
res
=
{
"res"
:
res_lst
}
return
res
ocr_service
=
OCRService
(
name
=
"ocr"
)
ocr_service
.
load_model_config
(
"ocr_rec_model"
)
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
init_rec
()
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
ocr_service
.
run_debugger_service
()
ocr_service
.
run_web_service
()
tools/serving_build.sh
浏览文件 @
30715e7b
...
@@ -183,25 +183,25 @@ function python_test_fit_a_line() {
...
@@ -183,25 +183,25 @@ function python_test_fit_a_line() {
# test web
# test web
unsetproxy
# maybe the proxy is used on iPipe, which makes web-test failed.
unsetproxy
# maybe the proxy is used on iPipe, which makes web-test failed.
check_cmd
"python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 2 --gpu_ids 0 --name uci > /dev/null &"
#
check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 2 --gpu_ids 0 --name uci > /dev/null &"
sleep
5
# wait for the server to start
#
sleep 5 # wait for the server to start
check_cmd
"curl -H
\"
Content-Type:application/json
\"
-X POST -d '{
\"
feed
\"
:[{
\"
x
\"
: [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}],
\"
fetch
\"
:[
\"
price
\"
]}' http://127.0.0.1:9393/uci/prediction"
#
check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
# check http code
# check http code
http_code
=
`
curl
-H
"Content-Type:application/json"
-X
POST
-d
'{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}'
-s
-w
"%{http_code}"
-o
/dev/null http://127.0.0.1:9393/uci/prediction
`
#
http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
if
[
${
http_code
}
-ne
200
]
;
then
#
if [ ${http_code} -ne 200 ]; then
echo
"HTTP status code -ne 200"
#
echo "HTTP status code -ne 200"
exit
1
#
exit 1
fi
#
fi
# test web batch
# test web batch
check_cmd
"curl -H
\"
Content-Type:application/json
\"
-X POST -d '{
\"
feed
\"
:[{
\"
x
\"
: [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {
\"
x
\"
: [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}],
\"
fetch
\"
:[
\"
price
\"
]}' http://127.0.0.1:9393/uci/prediction"
#
check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
# check http code
# check http code
http_code
=
`
curl
-H
"Content-Type:application/json"
-X
POST
-d
'{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}'
-s
-w
"%{http_code}"
-o
/dev/null http://127.0.0.1:9393/uci/prediction
`
#
http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}, {"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]}], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
if
[
${
http_code
}
-ne
200
]
;
then
#
if [ ${http_code} -ne 200 ]; then
echo
"HTTP status code -ne 200"
#
echo "HTTP status code -ne 200"
exit
1
#
exit 1
fi
#
fi
setproxy
# recover proxy state
setproxy
# recover proxy state
kill_server_process
#
kill_server_process
;;
;;
*
)
*
)
echo
"error type"
echo
"error type"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录