Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
826a7c38
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看板
未验证
提交
826a7c38
编写于
8月 15, 2020
作者:
J
Jiawei Wang
提交者:
GitHub
8月 15, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #788 from PaddlePaddle/cpu_webservice
add cpu webservice
上级
c047dc76
905ce94f
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
123 addition
and
36 deletion
+123
-36
python/examples/ocr/README.md
python/examples/ocr/README.md
+20
-7
python/examples/ocr/README_CN.md
python/examples/ocr/README_CN.md
+19
-12
python/examples/ocr/det_debugger_server.py
python/examples/ocr/det_debugger_server.py
+10
-3
python/examples/ocr/det_web_server.py
python/examples/ocr/det_web_server.py
+10
-3
python/examples/ocr/ocr_debugger_server.py
python/examples/ocr/ocr_debugger_server.py
+14
-4
python/examples/ocr/ocr_web_server.py
python/examples/ocr/ocr_web_server.py
+10
-3
python/examples/ocr/rec_web_server.py
python/examples/ocr/rec_web_server.py
+10
-3
python/paddle_serving_server/web_service.py
python/paddle_serving_server/web_service.py
+28
-0
python/requirements.txt
python/requirements.txt
+1
-0
python/setup.py.app.in
python/setup.py.app.in
+1
-1
未找到文件。
python/examples/ocr/README.md
浏览文件 @
826a7c38
...
...
@@ -21,8 +21,13 @@ tar xf test_imgs.tar
### Start Service
```
#choose one of cpu/gpu commands as following
#for cpu user
python -m paddle_serving_server.serve --model ocr_det_model --port 9293
python ocr_web_server.py cpu
#for gpu user
python -m paddle_serving_server_gpu.serve --model ocr_det_model --port 9293 --gpu_id 0
python ocr_web_server.py
python ocr_web_server.py
gpu
```
### Client Prediction
...
...
@@ -33,7 +38,11 @@ If you want a faster web service, please try Web Debugger Service
## Web Debugger Service
```
python ocr_debugger_server.py
#choose one of cpu/gpu commands as following
#for cpu user
python ocr_debugger_server.py cpu
#for gpu user
python ocr_debugger_server.py gpu
```
## Web Debugger Client Prediction
...
...
@@ -54,15 +63,17 @@ Dataset: RCTW 500 sample images
| Serving web service | 8.69 | 13.41 | 109.97 | 2.82 | 87.76 | 4.29 | 3.98 | 78.51 | 3.66 | 4.12 | 181.02 | 136.49 | 317.51 |
| Serving Debugger web service | 8.73 | 16.42 | 115.27 | 2.93 | 20.63 | 3.97 | 4.48 | 13.84 | 3.60 | 6.91 | 49.45 | 147.33 | 196.78 |
## Appendix: Det or Rec only
## Appendix:
For Users who want to launch
Det or Rec only
if you are going to detect images not recognize it or directly recognize the words from images. We also provide Det and Rec server for you.
### Det Server
```
python det_web_server.py
python det_web_server.py cpu #for cpu user
python det_web_server.py gpu #for gpu user
#or
python det_debugger_server.py
python det_debugger_server.py cpu #for cpu user
python det_debugger_server.py gpu #for gpu user
```
### Det Client
...
...
@@ -75,9 +86,11 @@ python ocr_web_client.py
### Rec Server
```
python rec_web_server.py
python rec_web_server.py cpu #for cpu user
python rec_web_server.py gpu #for gpu user
#or
python rec_debugger_server.py
python rec_debugger_server.py cpu #for cpu user
python rec_debugger_server.py gpu #for gpu user
```
### Rec Client
...
...
python/examples/ocr/README_CN.md
浏览文件 @
826a7c38
...
...
@@ -15,19 +15,18 @@ wget --no-check-certificate https://paddle-serving.bj.bcebos.com/ocr/test_imgs.t
tar xf test_imgs.tar
```
### 客户端预测
```
python ocr_rpc_client.py
```
## Web Service服务
### 启动服务
```
#根据CPU/GPU设备选择一种启动方式
#for cpu user
python -m paddle_serving_server.serve --model ocr_det_model --port 9293
python ocr_web_server.py cpu
#for gpu user
python -m paddle_serving_server_gpu.serve --model ocr_det_model --port 9293 --gpu_id 0
python ocr_web_server.py
python ocr_web_server.py
gpu
```
### 启动客户端
...
...
@@ -38,7 +37,11 @@ python ocr_web_client.py
如果用户需要更快的执行速度,请尝试Debugger版Web服务
## 启动Debugger版Web服务
```
python ocr_debugger_server.py
#根据CPU/GPU设备选择一种启动方式
#for cpu user
python ocr_debugger_server.py cpu
#for gpu user
python ocr_debugger_server.py gpu
```
## 启动客户端
...
...
@@ -66,9 +69,11 @@ GPU: Nvidia Tesla V100单卡
### 启动检测服务
```
python det_web_server.py
python det_web_server.py cpu #for cpu user
python det_web_server.py gpu #for gpu user
#or
python det_debugger_server.py
python det_debugger_server.py cpu #for cpu user
python det_debugger_server.py gpu #for gpu user
```
### 检测服务客户端
...
...
@@ -81,9 +86,11 @@ python ocr_web_client.py
### 启动识别服务
```
python rec_web_server.py
python rec_web_server.py cpu #for cpu user
python rec_web_server.py gpu #for gpu user
#or
python rec_debugger_server.py
python rec_debugger_server.py cpu #for cpu user
python rec_debugger_server.py gpu #for gpu user
```
### 识别服务客户端
...
...
python/examples/ocr/det_debugger_server.py
浏览文件 @
826a7c38
...
...
@@ -21,7 +21,10 @@ from paddle_serving_client import Client
from
paddle_serving_app.reader
import
Sequential
,
ResizeByFactor
from
paddle_serving_app.reader
import
Div
,
Normalize
,
Transpose
from
paddle_serving_app.reader
import
DBPostProcess
,
FilterBoxes
from
paddle_serving_server_gpu.web_service
import
WebService
if
sys
.
argv
[
1
]
==
'gpu'
:
from
paddle_serving_server_gpu.web_service
import
WebService
elif
sys
.
argv
[
1
]
==
'cpu'
:
from
paddle_serving_server.web_service
import
WebService
import
time
import
re
import
base64
...
...
@@ -64,8 +67,12 @@ class OCRService(WebService):
ocr_service
=
OCRService
(
name
=
"ocr"
)
ocr_service
.
load_model_config
(
"ocr_det_model"
)
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
if
sys
.
argv
[
1
]
==
'gpu'
:
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
elif
sys
.
argv
[
1
]
==
'cpu'
:
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
)
ocr_service
.
init_det
()
ocr_service
.
run_debugger_service
()
ocr_service
.
run_web_service
()
python/examples/ocr/det_web_server.py
浏览文件 @
826a7c38
...
...
@@ -21,7 +21,10 @@ from paddle_serving_client import Client
from
paddle_serving_app.reader
import
Sequential
,
ResizeByFactor
from
paddle_serving_app.reader
import
Div
,
Normalize
,
Transpose
from
paddle_serving_app.reader
import
DBPostProcess
,
FilterBoxes
from
paddle_serving_server_gpu.web_service
import
WebService
if
sys
.
argv
[
1
]
==
'gpu'
:
from
paddle_serving_server_gpu.web_service
import
WebService
elif
sys
.
argv
[
1
]
==
'cpu'
:
from
paddle_serving_server.web_service
import
WebService
import
time
import
re
import
base64
...
...
@@ -65,8 +68,12 @@ class OCRService(WebService):
ocr_service
=
OCRService
(
name
=
"ocr"
)
ocr_service
.
load_model_config
(
"ocr_det_model"
)
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
if
sys
.
argv
[
1
]
==
'gpu'
:
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
elif
sys
.
argv
[
1
]
==
'cpu'
:
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"cpu"
)
ocr_service
.
init_det
()
ocr_service
.
run_rpc_service
()
ocr_service
.
run_web_service
()
python/examples/ocr/ocr_debugger_server.py
浏览文件 @
826a7c38
...
...
@@ -22,7 +22,10 @@ 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
if
sys
.
argv
[
1
]
==
'gpu'
:
from
paddle_serving_server_gpu.web_service
import
WebService
elif
sys
.
argv
[
1
]
==
'cpu'
:
from
paddle_serving_server.web_service
import
WebService
from
paddle_serving_app.local_predict
import
Debugger
import
time
import
re
...
...
@@ -37,8 +40,12 @@ class OCRService(WebService):
(
2
,
0
,
1
))
])
self
.
det_client
=
Debugger
()
self
.
det_client
.
load_model_config
(
det_model_config
,
gpu
=
True
,
profile
=
False
)
if
sys
.
argv
[
1
]
==
'gpu'
:
self
.
det_client
.
load_model_config
(
det_model_config
,
gpu
=
True
,
profile
=
False
)
elif
sys
.
argv
[
1
]
==
'cpu'
:
self
.
det_client
.
load_model_config
(
det_model_config
,
gpu
=
False
,
profile
=
False
)
self
.
ocr_reader
=
OCRReader
()
def
preprocess
(
self
,
feed
=
[],
fetch
=
[]):
...
...
@@ -99,5 +106,8 @@ ocr_service = OCRService(name="ocr")
ocr_service
.
load_model_config
(
"ocr_rec_model"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
)
ocr_service
.
init_det_debugger
(
det_model_config
=
"ocr_det_model"
)
ocr_service
.
run_debugger_service
(
gpu
=
True
)
if
sys
.
argv
[
1
]
==
'gpu'
:
ocr_service
.
run_debugger_service
(
gpu
=
True
)
elif
sys
.
argv
[
1
]
==
'cpu'
:
ocr_service
.
run_debugger_service
()
ocr_service
.
run_web_service
()
python/examples/ocr/ocr_web_server.py
浏览文件 @
826a7c38
...
...
@@ -22,7 +22,10 @@ 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
if
sys
.
argv
[
1
]
==
'gpu'
:
from
paddle_serving_server_gpu.web_service
import
WebService
elif
sys
.
argv
[
1
]
==
'cpu'
:
from
paddle_serving_server.web_service
import
WebService
import
time
import
re
import
base64
...
...
@@ -90,8 +93,12 @@ class OCRService(WebService):
ocr_service
=
OCRService
(
name
=
"ocr"
)
ocr_service
.
load_model_config
(
"ocr_rec_model"
)
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
if
sys
.
argv
[
1
]
==
'gpu'
:
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
elif
sys
.
argv
[
1
]
==
'cpu'
:
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
)
ocr_service
.
init_det_client
(
det_port
=
9293
,
det_client_config
=
"ocr_det_client/serving_client_conf.prototxt"
)
...
...
python/examples/ocr/rec_web_server.py
浏览文件 @
826a7c38
...
...
@@ -22,7 +22,10 @@ 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
if
sys
.
argv
[
1
]
==
'gpu'
:
from
paddle_serving_server_gpu.web_service
import
WebService
elif
sys
.
argv
[
1
]
==
'cpu'
:
from
paddle_serving_server.web_service
import
WebService
import
time
import
re
import
base64
...
...
@@ -64,8 +67,12 @@ class OCRService(WebService):
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
)
if
sys
.
argv
[
1
]
==
'gpu'
:
ocr_service
.
set_gpus
(
"0"
)
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"gpu"
,
gpuid
=
0
)
elif
sys
.
argv
[
1
]
==
'cpu'
:
ocr_service
.
prepare_server
(
workdir
=
"workdir"
,
port
=
9292
,
device
=
"cpu"
)
ocr_service
.
run_rpc_service
()
ocr_service
.
run_web_service
()
python/paddle_serving_server/web_service.py
浏览文件 @
826a7c38
...
...
@@ -91,6 +91,8 @@ class WebService(object):
request
.
json
[
"fetch"
])
if
isinstance
(
feed
,
dict
)
and
"fetch"
in
feed
:
del
feed
[
"fetch"
]
if
len
(
feed
)
==
0
:
raise
ValueError
(
"empty input"
)
fetch_map
=
self
.
client
.
predict
(
feed
=
feed
,
fetch
=
fetch
)
result
=
self
.
postprocess
(
feed
=
request
.
json
[
"feed"
],
fetch
=
fetch
,
fetch_map
=
fetch_map
)
...
...
@@ -122,6 +124,32 @@ class WebService(object):
self
.
app_instance
=
app_instance
def
run_debugger_service
(
self
):
import
socket
localIP
=
socket
.
gethostbyname
(
socket
.
gethostname
())
print
(
"web service address:"
)
print
(
"http://{}:{}/{}/prediction"
.
format
(
localIP
,
self
.
port
,
self
.
name
))
app_instance
=
Flask
(
__name__
)
@
app_instance
.
before_first_request
def
init
():
self
.
_launch_local_predictor
()
service_name
=
"/"
+
self
.
name
+
"/prediction"
@
app_instance
.
route
(
service_name
,
methods
=
[
"POST"
])
def
run
():
return
self
.
get_prediction
(
request
)
self
.
app_instance
=
app_instance
def
_launch_local_predictor
(
self
):
from
paddle_serving_app.local_predict
import
Debugger
self
.
client
=
Debugger
()
self
.
client
.
load_model_config
(
"{}"
.
format
(
self
.
model_config
),
gpu
=
False
,
profile
=
False
)
def
run_web_service
(
self
):
self
.
app_instance
.
run
(
host
=
"0.0.0.0"
,
port
=
self
.
port
,
...
...
python/requirements.txt
浏览文件 @
826a7c38
...
...
@@ -3,6 +3,7 @@ wheel>=0.34.0, <0.35.0
setuptools>=44.1.0
opencv-python==4.2.0.32
google>=2.0.3
opencv-python==4.2.0.32
protobuf>=3.12.2
grpcio-tools>=1.28.1
grpcio>=1.28.1
...
...
python/setup.py.app.in
浏览文件 @
826a7c38
...
...
@@ -42,7 +42,7 @@ if '${PACK}' == 'ON':
REQUIRED_PACKAGES = [
'six >= 1.10.0', 'sentencepiece', 'opencv-python', 'pillow',
'six >= 1.10.0', 'sentencepiece', 'opencv-python
<=4.2.0.32
', 'pillow',
'shapely', 'pyclipper'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录