Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
cd0e0b21
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看板
提交
cd0e0b21
编写于
3月 30, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix demo for py3
上级
5607153c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
17 deletion
+21
-17
python/examples/imagenet/image_http_client.py
python/examples/imagenet/image_http_client.py
+7
-10
python/examples/imagenet/image_rpc_client.py
python/examples/imagenet/image_rpc_client.py
+2
-3
python/examples/imdb/imdb_reader.py
python/examples/imdb/imdb_reader.py
+12
-4
未找到文件。
python/examples/imagenet/image_http_client.py
浏览文件 @
cd0e0b21
...
...
@@ -17,10 +17,16 @@ import base64
import
json
import
time
import
os
import
sys
py_version
=
sys
.
version_info
[
0
]
def
predict
(
image_path
,
server
):
image
=
base64
.
b64encode
(
open
(
image_path
).
read
())
if
py_version
==
2
:
image
=
base64
.
b64encode
(
open
(
image_path
).
read
())
else
:
image
=
base64
.
b64encode
(
open
(
image_path
,
"rb"
).
read
()).
decode
(
"utf-8"
)
req
=
json
.
dumps
({
"image"
:
image
,
"fetch"
:
[
"score"
]})
r
=
requests
.
post
(
server
,
data
=
req
,
headers
=
{
"Content-Type"
:
"application/json"
})
...
...
@@ -28,15 +34,6 @@ def predict(image_path, server):
return
r
def
batch_predict
(
image_path
,
server
):
image
=
base64
.
b64encode
(
open
(
image_path
).
read
())
req
=
json
.
dumps
({
"image"
:
[
image
,
image
],
"fetch"
:
[
"score"
]})
r
=
requests
.
post
(
server
,
data
=
req
,
headers
=
{
"Content-Type"
:
"application/json"
})
print
(
r
.
json
()[
"result"
][
1
][
"score"
][
0
])
return
r
if
__name__
==
"__main__"
:
server
=
"http://127.0.0.1:9393/image/prediction"
image_list
=
os
.
listdir
(
"./image_data/n01440764/"
)
...
...
python/examples/imagenet/image_rpc_client.py
浏览文件 @
cd0e0b21
...
...
@@ -19,16 +19,15 @@ import time
client
=
Client
()
client
.
load_client_config
(
sys
.
argv
[
1
])
client
.
connect
([
"127.0.0.1:9
295
"
])
client
.
connect
([
"127.0.0.1:9
393
"
])
reader
=
ImageReader
()
start
=
time
.
time
()
for
i
in
range
(
1000
):
with
open
(
"./data/n01440764_10026.JPEG"
)
as
f
:
with
open
(
"./data/n01440764_10026.JPEG"
,
"rb"
)
as
f
:
img
=
f
.
read
()
img
=
reader
.
process_image
(
img
).
reshape
(
-
1
)
fetch_map
=
client
.
predict
(
feed
=
{
"image"
:
img
},
fetch
=
[
"score"
])
print
(
i
)
end
=
time
.
time
()
print
(
end
-
start
)
...
...
python/examples/imdb/imdb_reader.py
浏览文件 @
cd0e0b21
...
...
@@ -19,15 +19,23 @@ import paddle
import
re
import
paddle.fluid.incubate.data_generator
as
dg
py_version
=
sys
.
version_info
[
0
]
class
IMDBDataset
(
dg
.
MultiSlotDataGenerator
):
def
load_resource
(
self
,
dictfile
):
self
.
_vocab
=
{}
wid
=
0
with
open
(
dictfile
)
as
f
:
for
line
in
f
:
self
.
_vocab
[
line
.
strip
()]
=
wid
wid
+=
1
if
py_version
==
2
:
with
open
(
dictfile
)
as
f
:
for
line
in
f
:
self
.
_vocab
[
line
.
strip
()]
=
wid
wid
+=
1
else
:
with
open
(
dictfile
,
encoding
=
"utf-8"
)
as
f
:
for
line
in
f
:
self
.
_vocab
[
line
.
strip
()]
=
wid
wid
+=
1
self
.
_unk_id
=
len
(
self
.
_vocab
)
self
.
_pattern
=
re
.
compile
(
r
'(;|,|\.|\?|!|\s|\(|\))'
)
self
.
return_value
=
(
"words"
,
[
1
,
2
,
3
,
4
,
5
,
6
]),
(
"label"
,
[
0
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录