Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
efc8e6f5
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
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看板
未验证
提交
efc8e6f5
编写于
9月 10, 2019
作者:
B
Bin Long
提交者:
GitHub
9月 10, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #146 from ShenYuhan/release/v1.1.0
add user_home, fix ci
上级
285cca4c
a6dc0d83
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
159 addition
and
10 deletion
+159
-10
README.md
README.md
+3
-4
paddlehub/commands/config.py
paddlehub/commands/config.py
+136
-0
paddlehub/common/dir.py
paddlehub/common/dir.py
+20
-6
paddlehub/common/lock.py
paddlehub/common/lock.py
+0
-0
未找到文件。
README.md
浏览文件 @
efc8e6f5
...
...
@@ -174,4 +174,3 @@ print(res)
目前版本支持以下模型:词法分析LAC;情感分析Senta;目标检测SSD;图像分类ResNet, MobileNet, NASNet等。
*
迁移学习: 提供了基于预训练模型的Finetune API,用户通过少量代码即可完成迁移学习,包括BERT/ERNIE文本分类、序列标注、图像分类迁移等。
paddlehub/commands/config.py
0 → 100644
浏览文件 @
efc8e6f5
#coding:utf-8
# Copyright (c) 2019 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.
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
argparse
import
json
import
os
import
re
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.common.dir
import
CONF_HOME
from
paddlehub.common.server_config
import
default_server_config
class
ConfigCommand
(
BaseCommand
):
name
=
"config"
def
__init__
(
self
,
name
):
super
(
ConfigCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
description
=
"Configure PaddleHub."
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s [COMMAND]'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s'
,
add_help
=
True
)
self
.
parser
.
add_argument
(
"command"
)
self
.
parser
.
add_argument
(
"option"
,
nargs
=
"?"
)
self
.
parser
.
add_argument
(
"value"
,
nargs
=
"?"
)
@
staticmethod
def
show_config
():
print
(
"The current configuration is shown below."
)
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"r"
)
as
fp
:
print
(
json
.
dumps
(
json
.
load
(
fp
),
indent
=
4
))
@
staticmethod
def
set_server_url
(
server_url
):
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"r"
)
as
fp
:
config
=
json
.
load
(
fp
)
re_str
=
"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$"
if
re
.
match
(
re_str
,
server_url
)
is
not
None
:
config
[
"server_url"
]
=
list
([
server_url
])
ConfigCommand
.
set_config
(
config
)
else
:
print
(
"The format of the input url is invalid."
)
@
staticmethod
def
set_config
(
config
):
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"w"
)
as
fp
:
fp
.
write
(
json
.
dumps
(
config
))
print
(
"Set success! The current configuration is shown below."
)
print
(
json
.
dumps
(
config
,
indent
=
4
))
@
staticmethod
def
show_server_url
():
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"r"
)
as
fp
:
config
=
json
.
load
(
fp
)
print
(
config
[
"server_url"
])
@
staticmethod
def
show_log_level
():
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"r"
)
as
fp
:
print
(
json
.
load
(
fp
)[
"log_level"
])
@
staticmethod
def
set_log_level
(
level
):
if
level
not
in
[
"CRITICAL"
,
"FATAL"
,
"ERROR"
,
"WARN"
,
"WARNING"
,
"INFO"
,
"DEBUG"
,
"NOTSET"
]:
print
(
"Allowed values include: "
"CRITICAL, FATAL, ERROR, WARN, WARNING, INFO, DEBUG, NOTSET"
)
return
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"r"
)
as
fp
:
current_config
=
json
.
load
(
fp
)
with
open
(
os
.
path
.
join
(
CONF_HOME
,
"config.json"
),
"w"
)
as
fp
:
current_config
[
"log_level"
]
=
level
fp
.
write
(
json
.
dumps
(
current_config
))
print
(
"Set success! The current configuration is shown below."
)
print
(
json
.
dumps
(
current_config
,
indent
=
4
))
@
staticmethod
def
show_help
():
str
=
"config <option> <value>
\n
"
str
+=
"
\t
Show hub server config without any option.
\n
"
str
+=
"option:
\n
"
str
+=
"reset
\n
"
str
+=
"
\t
Reset config as default.
\n
"
str
+=
"server
\n
"
str
+=
"
\t
Show server url.
\n
"
str
+=
"server [URL]
\n
"
str
+=
"
\t
Set hub server url as [URL].
\n
"
str
+=
"log
\n
"
str
+=
"
\t
Show log level.
\n
"
str
+=
"log [LEVEL]
\n
"
str
+=
"
\t
Set log level as [LEVEL:NOLOG, DEBUG, INFO, WARNING, ERROR, CRITICAL].
\n
"
print
(
str
)
def
execute
(
self
,
argv
):
args
=
self
.
parser
.
parse_args
()
if
args
.
option
is
None
:
ConfigCommand
.
show_config
()
elif
args
.
option
==
"reset"
:
ConfigCommand
.
set_config
(
default_server_config
)
elif
args
.
option
==
"server"
:
if
args
.
value
is
not
None
:
ConfigCommand
.
set_server_url
(
args
.
value
)
else
:
ConfigCommand
.
show_server_url
()
elif
args
.
option
==
"log"
:
if
args
.
value
is
not
None
:
ConfigCommand
.
set_log_level
(
args
.
value
)
else
:
ConfigCommand
.
show_log_level
()
else
:
ConfigCommand
.
show_help
()
return
True
command
=
ConfigCommand
.
instance
()
paddlehub/common/dir.py
浏览文件 @
efc8e6f5
...
...
@@ -16,9 +16,23 @@
import
os
# TODO: Change dir.py's filename, this naming rule is not qualified
USER_HOME
=
os
.
path
.
expanduser
(
'~'
)
HUB_HOME
=
os
.
path
.
join
(
USER_HOME
,
".paddlehub"
)
MODULE_HOME
=
os
.
path
.
join
(
HUB_HOME
,
"modules"
)
CACHE_HOME
=
os
.
path
.
join
(
HUB_HOME
,
"cache"
)
DATA_HOME
=
os
.
path
.
join
(
HUB_HOME
,
"dataset"
)
CONF_HOME
=
os
.
path
.
join
(
HUB_HOME
,
"conf"
)
def
gen_user_home
():
if
"HUB_HOME"
in
os
.
environ
:
home_path
=
os
.
environ
[
"HUB_HOME"
]
if
os
.
path
.
exists
(
home_path
)
and
os
.
path
.
isdir
(
home_path
):
return
home_path
return
os
.
path
.
expanduser
(
'~'
)
def
gen_hub_home
():
return
os
.
path
.
join
(
gen_user_home
(),
".paddlehub"
)
USER_HOME
=
gen_user_home
()
HUB_HOME
=
gen_hub_home
()
MODULE_HOME
=
os
.
path
.
join
(
gen_hub_home
(),
"modules"
)
CACHE_HOME
=
os
.
path
.
join
(
gen_hub_home
(),
"cache"
)
DATA_HOME
=
os
.
path
.
join
(
gen_hub_home
(),
"dataset"
)
CONF_HOME
=
os
.
path
.
join
(
gen_hub_home
(),
"conf"
)
paddlehub/common/lock.py
0 → 100644
浏览文件 @
efc8e6f5
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录