Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
a8bc5b36
S
Serving
项目概览
PaddlePaddle
/
Serving
12 个月 前同步成功
通知
183
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a8bc5b36
编写于
3月 04, 2020
作者:
M
MRXLT
提交者:
GitHub
3月 04, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #229 from guru4elephant/refine_fit_a_line
add WebService, fix imdb,fit-a-line example
上级
ef7c7a5a
0a33d86d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
175 addition
and
19 deletion
+175
-19
python/examples/fit_a_line/README.md
python/examples/fit_a_line/README.md
+22
-0
python/examples/fit_a_line/get_data.sh
python/examples/fit_a_line/get_data.sh
+2
-0
python/examples/fit_a_line/test_client.py
python/examples/fit_a_line/test_client.py
+3
-3
python/examples/fit_a_line/test_server.py
python/examples/fit_a_line/test_server.py
+3
-1
python/examples/imdb/imdb_web_service_demo.sh
python/examples/imdb/imdb_web_service_demo.sh
+6
-0
python/examples/imdb/local_train.py
python/examples/imdb/local_train.py
+1
-1
python/examples/imdb/text_classify_service.py
python/examples/imdb/text_classify_service.py
+12
-14
python/paddle_serving_server/web_serve.py
python/paddle_serving_server/web_serve.py
+39
-0
python/paddle_serving_server/web_service.py
python/paddle_serving_server/web_service.py
+85
-0
python/setup.py.server.in
python/setup.py.server.in
+1
-0
python/setup.py.server_gpu.in
python/setup.py.server_gpu.in
+1
-0
未找到文件。
python/examples/fit_a_line/README.md
0 → 100644
浏览文件 @
a8bc5b36
# Fit a line example, prediction through rpc service
Start rpc service
```
shell
sh get_data.sh
python test_server.py uci_housing_model/
```
Prediction
```
shell
python test_client.py uci_housing_client/serving_client_conf.prototxt
```
# prediction through http service
Start a web service with default web service hosting modules
```
shell
python
-m
paddle_serving_server.web_serve
--model
uci_housing_model/
--thread
10
--name
uci
--port
9393
--name
uci
```
Prediction through http post
```
shell
curl
-H
"Content-Type:application/json"
-X
POST
-d
'{"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
```
\ No newline at end of file
python/examples/fit_a_line/get_data.sh
0 → 100644
浏览文件 @
a8bc5b36
wget
--no-check-certificate
https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
tar
-xzf
uci_housing.tar.gz
python/examples/fit_a_line/test_client.py
浏览文件 @
a8bc5b36
...
...
@@ -4,12 +4,12 @@ import sys
client
=
Client
()
client
.
load_client_config
(
sys
.
argv
[
1
])
client
.
connect
([
"127.0.0.1:9
292
"
])
client
.
connect
([
"127.0.0.1:9
393
"
])
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
1
)
for
data
in
test_reader
():
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"
y
"
])
print
(
"{} {}"
.
format
(
fetch_map
[
"
y
"
][
0
],
data
[
0
][
1
][
0
]))
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"
price
"
])
print
(
"{} {}"
.
format
(
fetch_map
[
"
price
"
][
0
],
data
[
0
][
1
][
0
]))
python/examples/fit_a_line/test_server.py
浏览文件 @
a8bc5b36
...
...
@@ -7,13 +7,15 @@ from paddle_serving_server import Server
op_maker
=
OpMaker
()
read_op
=
op_maker
.
create
(
'general_reader'
)
general_infer_op
=
op_maker
.
create
(
'general_infer'
)
response_op
=
op_maker
.
create
(
'general_response'
)
op_seq_maker
=
OpSeqMaker
()
op_seq_maker
.
add_op
(
read_op
)
op_seq_maker
.
add_op
(
general_infer_op
)
op_seq_maker
.
add_op
(
response_op
)
server
=
Server
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
server
.
load_model_config
(
sys
.
argv
[
1
])
server
.
prepare_server
(
workdir
=
"work_dir1"
,
port
=
9
292
,
device
=
"cpu"
)
server
.
prepare_server
(
workdir
=
"work_dir1"
,
port
=
9
393
,
device
=
"cpu"
)
server
.
run_server
()
python/examples/imdb/imdb_web_service_demo.sh
0 → 100644
浏览文件 @
a8bc5b36
wget https://paddle-serving.bj.bcebos.com/imdb-demo%2Fimdb_service.tar.gz
tar
-xzf
imdb_service.tar.gz
wget
--no-check-certificate
https://fleet.bj.bcebos.com/text_classification_data.tar.gz
tar
-zxvf
text_classification_data.tar.gz
python text_classify_service.py serving_server_model/ workdir imdb.vocab
python/examples/imdb/local_train.py
浏览文件 @
a8bc5b36
...
...
@@ -65,6 +65,6 @@ if __name__ == "__main__":
program
=
fluid
.
default_main_program
(),
dataset
=
dataset
,
debug
=
False
)
logger
.
info
(
"TRAIN --> pass: {}"
.
format
(
i
))
if
i
==
5
:
serving_io
.
save_model
(
"
serving_server_model"
,
"serving
_client_conf"
,
serving_io
.
save_model
(
"
imdb_model"
,
"imdb
_client_conf"
,
{
"words"
:
data
},
{
"prediction"
:
prediction
},
fluid
.
default_main_program
())
python/examples/imdb/text_classify_service.py
浏览文件 @
a8bc5b36
...
...
@@ -12,28 +12,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#!flask/bin/python
from
plugin_service
import
PluginService
from
paddle_serving_server.web_service
import
WebService
from
imdb_reader
import
IMDBDataset
import
sys
class
IMDBService
(
Plugin
Service
):
def
prepare_
service
(
self
,
args
=
{}):
class
IMDBService
(
Web
Service
):
def
prepare_
dict
(
self
,
args
=
{}):
if
len
(
args
)
==
0
:
exit
(
-
1
)
self
.
word_dict
=
{}
with
open
(
args
[
"dict_file_path"
])
as
fin
:
idx
=
0
for
line
in
fin
:
self
.
word_dict
[
idx
]
=
idx
idx
+=
1
self
.
dataset
=
IMDBDataset
()
self
.
dataset
.
load_resource
(
args
[
"dict_file_path"
])
def
preprocess
(
self
,
feed
=
{},
fetch
=
[]):
if
"words"
not
in
feed
:
exit
(
-
1
)
res_feed
=
{}
res_feed
[
"words"
]
=
[
self
.
word_dict
[
int
(
x
)]
for
x
in
feed
[
"words"
]]
print
(
res_feed
)
res_feed
[
"words"
]
=
self
.
dataset
.
get_words_and_label
(
feed
[
"words"
])[
0
]
return
res_feed
,
fetch
imdb_service
=
IMDBService
(
name
=
"imdb"
,
model
=
sys
.
argv
[
1
],
port
=
9898
)
imdb_service
.
prepare_service
({
"dict_file_path"
:
sys
.
argv
[
2
]})
imdb_service
.
start_service
()
imdb_service
=
IMDBService
(
name
=
"imdb"
)
imdb_service
.
load_model_config
(
sys
.
argv
[
1
])
imdb_service
.
prepare_server
(
workdir
=
sys
.
argv
[
2
],
port
=
9393
,
device
=
"cpu"
)
imdb_service
.
prepare_dict
({
"dict_file_path"
:
sys
.
argv
[
3
]})
imdb_service
.
run_server
()
python/paddle_serving_server/web_serve.py
0 → 100644
浏览文件 @
a8bc5b36
# 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.
"""
Usage:
Host a trained paddle model with one line command
Example:
python -m paddle_serving_server.web_serve --model ./serving_server_model --port 9292
"""
import
argparse
from
multiprocessing
import
Pool
,
Process
from
.web_service
import
WebService
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
"web_serve"
)
parser
.
add_argument
(
"--thread"
,
type
=
int
,
default
=
10
,
help
=
"Concurrency of server"
)
parser
.
add_argument
(
"--model"
,
type
=
str
,
default
=
""
,
help
=
"Model for serving"
)
parser
.
add_argument
(
"--port"
,
type
=
int
,
default
=
9292
,
help
=
"Port the server"
)
parser
.
add_argument
(
"--workdir"
,
type
=
str
,
default
=
"workdir"
,
help
=
"Working dir of current service"
)
parser
.
add_argument
(
"--device"
,
type
=
str
,
default
=
"cpu"
,
help
=
"Type of device"
)
parser
.
add_argument
(
"--name"
,
type
=
str
,
default
=
"default"
,
help
=
"Default service name"
)
return
parser
.
parse_args
()
if
__name__
==
"__main__"
:
args
=
parse_args
()
service
=
WebService
(
name
=
args
.
name
)
service
.
load_model_config
(
args
.
model
)
service
.
prepare_server
(
workdir
=
args
.
workdir
,
port
=
args
.
port
,
device
=
args
.
device
)
service
.
run_server
()
python/paddle_serving_server/
plugin
_service.py
→
python/paddle_serving_server/
web
_service.py
浏览文件 @
a8bc5b36
...
...
@@ -13,37 +13,69 @@
# limitations under the License.
#!flask/bin/python
from
flask
import
Flask
,
request
,
abort
from
multiprocessing
import
Pool
,
Process
from
paddle_serving_server
import
OpMaker
,
OpSeqMaker
,
Server
from
paddle_serving_client
import
Client
class
PluginService
(
object
):
def
__init__
(
self
,
name
=
"default_service"
,
model
=
""
,
port
=
9091
,
concurrency
=
10
):
class
WebService
(
object
):
def
__init__
(
self
,
name
=
"default_service"
):
self
.
name
=
name
self
.
port
=
port
self
.
model
=
model
self
.
concurrency
=
concurrency
def
prepare_service
(
self
,
args
=
{}
):
return
def
load_model_config
(
self
,
model_config
):
self
.
model_config
=
model_config
def
start_service
(
self
):
app_instance
=
Flask
(
__name__
)
self
.
client_service
=
Client
()
self
.
client_service
.
load_client_config
(
"{}/serving_server_conf.prototxt"
.
format
(
self
.
model
))
self
.
client_service
.
connect
([
"127.0.0.1:9292"
])
def
_launch_rpc_service
(
self
):
op_maker
=
OpMaker
()
read_op
=
op_maker
.
create
(
'general_reader'
)
general_infer_op
=
op_maker
.
create
(
'general_infer'
)
general_response_op
=
op_maker
.
create
(
'general_response'
)
op_seq_maker
=
OpSeqMaker
()
op_seq_maker
.
add_op
(
read_op
)
op_seq_maker
.
add_op
(
general_infer_op
)
op_seq_maker
.
add_op
(
general_response_op
)
server
=
Server
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
server
.
set_num_threads
(
16
)
server
.
load_model_config
(
self
.
model_config
)
server
.
prepare_server
(
workdir
=
self
.
workdir
,
port
=
self
.
port
+
1
,
device
=
self
.
device
)
server
.
run_server
()
def
prepare_server
(
self
,
workdir
=
""
,
port
=
9393
,
device
=
"cpu"
):
self
.
workdir
=
workdir
self
.
port
=
port
self
.
device
=
device
@
app_instance
.
route
(
'/PaddleServing/v1.0/prediction'
,
methods
=
[
'POST'
])
def
_launch_web_service
(
self
):
app_instance
=
Flask
(
__name__
)
client_service
=
Client
()
client_service
.
load_client_config
(
"{}/serving_server_conf.prototxt"
.
format
(
self
.
model_config
))
client_service
.
connect
([
"127.0.0.1:{}"
.
format
(
self
.
port
+
1
)])
service_name
=
"/"
+
self
.
name
+
"/prediction"
@
app_instance
.
route
(
service_name
,
methods
=
[
'POST'
])
def
get_prediction
():
if
not
request
.
json
:
abort
(
400
)
if
"fetch"
not
in
request
.
json
:
abort
(
400
)
feed
,
fetch
=
self
.
preprocess
(
request
.
json
,
request
.
json
[
"fetch"
])
fetch_map
=
self
.
client_service
.
predict
(
feed
=
feed
,
fetch
=
fetch
)
fetch_map
=
client_service
.
predict
(
feed
=
feed
,
fetch
=
fetch
)
fetch_map
=
self
.
postprocess
(
feed
=
request
.
json
,
fetch
=
fetch
,
fetch_map
=
fetch_map
)
app_instance
.
run
(
host
=
"127.0.0.1"
,
port
=
self
.
port
,
threaded
=
False
,
processes
=
1
)
return
fetch_map
app_instance
.
run
(
host
=
"127.0.0.1"
,
port
=
self
.
port
,
threaded
=
False
,
processes
=
1
)
def
run_server
(
self
):
import
socket
localIP
=
socket
.
gethostbyname
(
socket
.
gethostname
())
print
(
"web service address:"
)
print
(
"http://{}:{}/{}/prediction"
.
format
(
localIP
,
self
.
port
,
self
.
name
))
p_rpc
=
Process
(
target
=
self
.
_launch_rpc_service
)
p_web
=
Process
(
target
=
self
.
_launch_web_service
)
p_rpc
.
start
()
p_web
.
start
()
p_web
.
join
()
p_rpc
.
join
()
def
preprocess
(
self
,
feed
=
{},
fetch
=
[]):
return
feed
,
fetch
...
...
python/setup.py.server.in
浏览文件 @
a8bc5b36
...
...
@@ -30,6 +30,7 @@ max_version, mid_version, min_version = python_version()
REQUIRED_PACKAGES = [
'six >= 1.10.0', 'protobuf >= 3.1.0','paddlepaddle',
'paddle_serving_client'
]
packages=['paddle_serving_server',
...
...
python/setup.py.server_gpu.in
浏览文件 @
a8bc5b36
...
...
@@ -30,6 +30,7 @@ max_version, mid_version, min_version = python_version()
REQUIRED_PACKAGES = [
'six >= 1.10.0', 'protobuf >= 3.1.0','paddlepaddle',
'paddle_serving_client'
]
packages=['paddle_serving_server_gpu',
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录