Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
61314e59
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
61314e59
编写于
3月 28, 2020
作者:
L
LaraStuStu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Create __init__.py
上级
62bbcbf3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
0 deletion
+79
-0
DataAnnotation/labelme/labelme/config/__init__.py
DataAnnotation/labelme/labelme/config/__init__.py
+79
-0
未找到文件。
DataAnnotation/labelme/labelme/config/__init__.py
0 → 100644
浏览文件 @
61314e59
import
os.path
as
osp
import
shutil
import
yaml
from
labelme.logger
import
logger
here
=
osp
.
dirname
(
osp
.
abspath
(
__file__
))
def
update_dict
(
target_dict
,
new_dict
,
validate_item
=
None
):
for
key
,
value
in
new_dict
.
items
():
if
validate_item
:
validate_item
(
key
,
value
)
if
key
not
in
target_dict
:
logger
.
warn
(
'Skipping unexpected key in config: {}'
.
format
(
key
))
continue
if
isinstance
(
target_dict
[
key
],
dict
)
and
\
isinstance
(
value
,
dict
):
update_dict
(
target_dict
[
key
],
value
,
validate_item
=
validate_item
)
else
:
target_dict
[
key
]
=
value
# -----------------------------------------------------------------------------
def
get_default_config
():
config_file
=
osp
.
join
(
here
,
'default_config.yaml'
)
with
open
(
config_file
)
as
f
:
config
=
yaml
.
safe_load
(
f
)
# save default config to ~/.labelmerc
user_config_file
=
osp
.
join
(
osp
.
expanduser
(
'~'
),
'.labelmerc'
)
if
not
osp
.
exists
(
user_config_file
):
try
:
shutil
.
copy
(
config_file
,
user_config_file
)
except
Exception
:
logger
.
warn
(
'Failed to save config: {}'
.
format
(
user_config_file
))
return
config
def
validate_config_item
(
key
,
value
):
if
key
==
'validate_label'
and
value
not
in
[
None
,
'exact'
,
'instance'
]:
raise
ValueError
(
"Unexpected value for config key 'validate_label': {}"
.
format
(
value
)
)
if
key
==
'labels'
and
value
is
not
None
and
len
(
value
)
!=
len
(
set
(
value
)):
raise
ValueError
(
"Duplicates are detected for config key 'labels': {}"
.
format
(
value
)
)
def
get_config
(
config_from_args
=
None
,
config_file
=
None
):
# Configuration load order:
#
# 1. default config (lowest priority)
# 2. config file passed by command line argument or ~/.labelmerc
# 3. command line argument (highest priority)
# 1. default config
config
=
get_default_config
()
# 2. config from yaml file
if
config_file
is
not
None
and
osp
.
exists
(
config_file
):
with
open
(
config_file
)
as
f
:
user_config
=
yaml
.
safe_load
(
f
)
or
{}
update_dict
(
config
,
user_config
,
validate_item
=
validate_config_item
)
# 3. command line argument
if
config_from_args
is
not
None
:
update_dict
(
config
,
config_from_args
,
validate_item
=
validate_config_item
)
return
config
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录