Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
c3b0b213
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看板
提交
c3b0b213
编写于
3月 13, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine imdb demo
上级
4bfa908b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
47 addition
and
27 deletion
+47
-27
python/examples/bert/benchmark.py
python/examples/bert/benchmark.py
+1
-2
python/examples/imdb/README.md
python/examples/imdb/README.md
+22
-8
python/examples/imdb/benchmark.py
python/examples/imdb/benchmark.py
+17
-11
python/examples/imdb/local_train.py
python/examples/imdb/local_train.py
+2
-2
python/examples/imdb/test_client.py
python/examples/imdb/test_client.py
+2
-2
python/examples/imdb/text_classify_service.py
python/examples/imdb/text_classify_service.py
+3
-2
未找到文件。
python/examples/bert/benchmark.py
浏览文件 @
c3b0b213
...
...
@@ -58,7 +58,6 @@ def single_func(idx, resource):
else
:
print
(
"unsupport batch size {}"
.
format
(
args
.
batch_size
))
end
=
time
.
time
()
elif
args
.
request
==
"http"
:
start
=
time
.
time
()
header
=
{
"Content-Type"
:
"application/json"
}
...
...
@@ -69,7 +68,7 @@ def single_func(idx, resource):
idx
%
len
(
resource
[
"endpoint"
])]),
data
=
json
.
dumps
(
dict_data
),
headers
=
header
)
end
=
time
.
time
()
end
=
time
.
time
()
return
[[
end
-
start
]]
...
...
python/examples/imdb/README.md
浏览文件 @
c3b0b213
##
# 使用方法
##
IMDB评论情绪预测服务
假设数据文件为test.data,配置文件为inference.conf
单进程client
### 获取模型文件和样例数据
```
sh get_data.sh
```
脚本会下载和解压出cnn、lstm和bow三种模型的配置文文件以及test_data和train_data。
### 启动RPC预测服务
```
cat test.data | python test_client.py inference.conf > result
python -m paddle_serving_server.serve --model imdb_bow_model/ --port 9292
```
多进程client,若进程数为4
### 执行预测
```
python test_client_multithread.py inference.conf test.data 4 > result
head test_data/part-0 | python test_client.py imdb_lstm_client_conf/serving_client_conf.prototxt imdb.vocab
```
batch clienit,若batch size为4
预测test_data/part-0的前十个样例。
### 启动HTTP预测服务
```
python text_classify_service.py imdb_cnn_model/ workdir/ 9292 imdb.vocab
```
### 执行预测
```
c
at test.data | python test_client_batch.py inference.conf 4 > result
c
url -H "Content-Type:application/json" -X POST -d '{"words": "i am very sad | 0", "fetch":["prediction"]}' http://127.0.0.1:9292/imdb/prediction
```
### Benchmark
...
...
python/examples/imdb/benchmark.py
浏览文件 @
c3b0b213
...
...
@@ -26,24 +26,30 @@ args = benchmark_args()
def
single_func
(
idx
,
resource
):
imdb_dataset
=
IMDBDataset
()
imdb_dataset
.
load_resource
(
args
.
vocab
)
filelist_fn
=
args
.
filelist
filelist
=
[]
start
=
time
.
time
()
with
open
(
filelist_fn
)
as
fin
:
imdb_dataset
.
load_resource
(
"./imdb.vocab"
)
dataset
=
[]
with
open
(
"./test_data/part-0"
)
as
fin
:
for
line
in
fin
:
filelis
t
.
append
(
line
.
strip
())
filelist
=
filelist
[
idx
::
args
.
thread
]
datase
t
.
append
(
line
.
strip
())
start
=
time
.
time
()
if
args
.
request
==
"rpc"
:
client
=
Client
()
client
.
load_client_config
(
args
.
model
)
client
.
connect
([
args
.
endpoint
])
for
fn
in
filelist
:
fin
=
open
(
fn
)
for
line
in
fin
:
word_ids
,
label
=
imdb_dataset
.
get_words_and_label
(
line
)
for
i
in
range
(
1000
):
word_ids
,
label
=
imdb_dataset
.
get_words_and_label
(
line
)
if
args
.
batch_size
==
1
:
fetch_map
=
client
.
predict
(
feed
=
{
"words"
:
word_ids
},
fetch
=
[
"prediction"
])
elif
args
.
batch_size
>
1
:
feed_batch
=
[]
for
bi
in
range
(
args
.
batch_size
):
feed_batch
.
append
({
"words"
:
word_ids
})
result
=
client
.
batch_predict
(
feed_batch
=
feed_batch
,
fetch
=
[
"prediction"
])
else
:
print
(
"unsupport batch size {}"
.
format
(
args
.
batch_size
))
elif
args
.
request
==
"http"
:
for
fn
in
filelist
:
fin
=
open
(
fn
)
...
...
python/examples/imdb/local_train.py
浏览文件 @
c3b0b213
...
...
@@ -35,6 +35,8 @@ def load_vocab(filename):
if
__name__
==
"__main__"
:
from
nets
import
lstm_net
model_name
=
"imdb_lstm"
vocab
=
load_vocab
(
'imdb.vocab'
)
dict_dim
=
len
(
vocab
)
...
...
@@ -50,8 +52,6 @@ if __name__ == "__main__":
dataset
.
set_batch_size
(
128
)
dataset
.
set_filelist
(
filelist
)
dataset
.
set_thread
(
10
)
from
nets
import
lstm_net
model_name
=
"imdb_lstm"
avg_cost
,
acc
,
prediction
=
lstm_net
(
data
,
label
,
dict_dim
)
optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.01
)
optimizer
.
minimize
(
avg_cost
)
...
...
python/examples/imdb/test_client.py
浏览文件 @
c3b0b213
...
...
@@ -18,7 +18,7 @@ import sys
client
=
Client
()
client
.
load_client_config
(
sys
.
argv
[
1
])
client
.
connect
([
"127.0.0.1:9
393
"
])
client
.
connect
([
"127.0.0.1:9
292
"
])
# you can define any english sentence or dataset here
# This example reuses imdb reader in training, you
...
...
@@ -28,7 +28,7 @@ imdb_dataset.load_resource(sys.argv[2])
for
line
in
sys
.
stdin
:
word_ids
,
label
=
imdb_dataset
.
get_words_and_label
(
line
)
feed
=
{
"words"
:
word_ids
,
"label"
:
label
}
feed
=
{
"words"
:
word_ids
}
fetch
=
[
"acc"
,
"cost"
,
"prediction"
]
fetch_map
=
client
.
predict
(
feed
=
feed
,
fetch
=
fetch
)
print
(
"{} {}"
.
format
(
fetch_map
[
"prediction"
][
1
],
label
[
0
]))
python/examples/imdb/text_classify_service.py
浏览文件 @
c3b0b213
...
...
@@ -35,6 +35,7 @@ class IMDBService(WebService):
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
.
prepare_server
(
workdir
=
sys
.
argv
[
2
],
port
=
int
(
sys
.
argv
[
3
]),
device
=
"cpu"
)
imdb_service
.
prepare_dict
({
"dict_file_path"
:
sys
.
argv
[
4
]})
imdb_service
.
run_server
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录