Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
ed1c6e8b
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 2 年 前同步成功
通知
285
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ed1c6e8b
编写于
6月 26, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update module api to support gpu and batch_size config
上级
04308cee
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
12 deletion
+27
-12
demo/lac/lac_demo.py
demo/lac/lac_demo.py
+1
-1
paddlehub/commands/run.py
paddlehub/commands/run.py
+18
-1
paddlehub/module/module.py
paddlehub/module/module.py
+8
-10
未找到文件。
demo/lac/lac_demo.py
浏览文件 @
ed1c6e8b
...
@@ -16,7 +16,7 @@ if __name__ == "__main__":
...
@@ -16,7 +16,7 @@ if __name__ == "__main__":
inputs
=
{
"text"
:
test_text
}
inputs
=
{
"text"
:
test_text
}
# execute predict and print the result
# execute predict and print the result
results
=
lac
.
lexical_analysis
(
data
=
inputs
)
results
=
lac
.
lexical_analysis
(
data
=
inputs
,
use_gpu
=
True
,
batch_size
=
10
)
for
result
in
results
:
for
result
in
results
:
if
six
.
PY2
:
if
six
.
PY2
:
print
(
print
(
...
...
paddlehub/commands/run.py
浏览文件 @
ed1c6e8b
...
@@ -21,6 +21,7 @@ import argparse
...
@@ -21,6 +21,7 @@ import argparse
import
json
import
json
import
os
import
os
import
sys
import
sys
import
ast
import
six
import
six
import
pandas
import
pandas
...
@@ -80,6 +81,18 @@ class RunCommand(BaseCommand):
...
@@ -80,6 +81,18 @@ class RunCommand(BaseCommand):
default
=
config
[
'default'
],
default
=
config
[
'default'
],
help
=
config
[
'help'
])
help
=
config
[
'help'
])
self
.
arg_config_group
.
add_argument
(
'--use_gpu'
,
type
=
ast
.
literal_eval
,
default
=
False
,
help
=
"whether use GPU for prediction"
)
self
.
arg_config_group
.
add_argument
(
'--batch_size'
,
type
=
int
,
default
=
1
,
help
=
"batch size for prediction"
)
self
.
arg_config_group
.
add_argument
(
self
.
arg_config_group
.
add_argument
(
'--config'
,
'--config'
,
type
=
str
,
type
=
str
,
...
@@ -224,7 +237,11 @@ class RunCommand(BaseCommand):
...
@@ -224,7 +237,11 @@ class RunCommand(BaseCommand):
return
False
return
False
results
=
self
.
module
(
results
=
self
.
module
(
sign_name
=
self
.
module
.
default_signature
.
name
,
data
=
data
,
**
config
)
sign_name
=
self
.
module
.
default_signature
.
name
,
data
=
data
,
use_gpu
=
self
.
args
.
use_gpu
,
batch_size
=
self
.
args
.
batch_size
,
**
config
)
if
six
.
PY2
:
if
six
.
PY2
:
try
:
try
:
...
...
paddlehub/module/module.py
浏览文件 @
ed1c6e8b
...
@@ -434,7 +434,7 @@ class Module(object):
...
@@ -434,7 +434,7 @@ class Module(object):
for
key
,
value
in
self
.
extra_info
.
items
():
for
key
,
value
in
self
.
extra_info
.
items
():
utils
.
from_pyobj_to_module_attr
(
value
,
extra_info
.
map
.
data
[
key
])
utils
.
from_pyobj_to_module_attr
(
value
,
extra_info
.
map
.
data
[
key
])
def
__call__
(
self
,
sign_name
,
data
,
**
kwargs
):
def
__call__
(
self
,
sign_name
,
data
,
use_gpu
=
False
,
batch_size
=
1
,
**
kwargs
):
self
.
check_processor
()
self
.
check_processor
()
def
_get_reader_and_feeder
(
data_format
,
data
,
place
):
def
_get_reader_and_feeder
(
data_format
,
data
,
place
):
...
@@ -463,15 +463,13 @@ class Module(object):
...
@@ -463,15 +463,13 @@ class Module(object):
with
fluid
.
program_guard
(
program
):
with
fluid
.
program_guard
(
program
):
result
=
[]
result
=
[]
index
=
0
index
=
0
if
"PADDLEHUB_CUDA_ENABLE"
in
os
.
environ
:
try
:
place
=
fluid
.
CUDAPlace
(
0
)
_places
=
os
.
environ
[
"CUDA_VISIBLE_DEVICES"
]
else
:
int
(
_places
[
0
])
place
=
fluid
.
CPUPlace
()
except
:
use_gpu
=
False
if
"PADDLEHUB_BATCH_SIZE"
in
os
.
environ
:
batch_size
=
os
.
environ
[
"PADDLEHUB_BATCH_SIZE"
]
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
else
:
batch_size
=
1
exe
=
fluid
.
Executor
(
place
=
place
)
exe
=
fluid
.
Executor
(
place
=
place
)
data
=
self
.
processor
.
preprocess
(
data
=
self
.
processor
.
preprocess
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录