Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
c04eea1e
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c04eea1e
编写于
10月 22, 2020
作者:
J
Jonathan Huang
提交者:
TF Object Detection Team
10月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support in label map proto for LVIS specific fields.
PiperOrigin-RevId: 338526646
上级
aca137c1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
72 addition
and
6 deletion
+72
-6
research/object_detection/protos/string_int_label_map.proto
research/object_detection/protos/string_int_label_map.proto
+12
-0
research/object_detection/utils/label_map_util.py
research/object_detection/utils/label_map_util.py
+12
-0
research/object_detection/utils/label_map_util_test.py
research/object_detection/utils/label_map_util_test.py
+48
-6
未找到文件。
research/object_detection/protos/string_int_label_map.proto
浏览文件 @
c04eea1e
...
...
@@ -6,6 +6,14 @@ syntax = "proto2";
package
object_detection
.
protos
;
// LVIS frequency:
enum
LVISFrequency
{
UNSPECIFIED
=
0
;
FREQUENT
=
1
;
COMMON
=
2
;
RARE
=
3
;
}
message
StringIntLabelMapItem
{
// String name. The most common practice is to set this to a MID or synsets
// id.
...
...
@@ -38,6 +46,10 @@ message StringIntLabelMapItem {
// current element. Value should correspond to another label id element.
repeated
int32
ancestor_ids
=
5
;
repeated
int32
descendant_ids
=
6
;
// LVIS specific label map fields
optional
LVISFrequency
frequency
=
7
;
optional
int32
instance_count
=
8
;
};
message
StringIntLabelMap
{
...
...
research/object_detection/utils/label_map_util.py
浏览文件 @
c04eea1e
...
...
@@ -130,6 +130,18 @@ def convert_label_map_to_categories(label_map,
if
item
.
id
not
in
list_of_ids_already_added
:
list_of_ids_already_added
.
append
(
item
.
id
)
category
=
{
'id'
:
item
.
id
,
'name'
:
name
}
if
item
.
HasField
(
'frequency'
):
if
item
.
frequency
==
string_int_label_map_pb2
.
LVISFrequency
.
Value
(
'FREQUENT'
):
category
[
'frequency'
]
=
'f'
elif
item
.
frequency
==
string_int_label_map_pb2
.
LVISFrequency
.
Value
(
'COMMON'
):
category
[
'frequency'
]
=
'c'
elif
item
.
frequency
==
string_int_label_map_pb2
.
LVISFrequency
.
Value
(
'RARE'
):
category
[
'frequency'
]
=
'r'
if
item
.
HasField
(
'instance_count'
):
category
[
'instance_count'
]
=
item
.
instance_count
if
item
.
keypoints
:
keypoints
=
{}
list_of_keypoint_ids
=
[]
...
...
research/object_detection/utils/label_map_util_test.py
浏览文件 @
c04eea1e
...
...
@@ -201,7 +201,7 @@ class LabelMapUtilTest(tf.test.TestCase):
name:'n00007846'
}
"""
text_format
.
Merg
e
(
label_map_string
,
label_map_proto
)
text_format
.
Pars
e
(
label_map_string
,
label_map_proto
)
categories
=
label_map_util
.
convert_label_map_to_categories
(
label_map_proto
,
max_num_classes
=
3
)
self
.
assertListEqual
([{
...
...
@@ -227,19 +227,61 @@ class LabelMapUtilTest(tf.test.TestCase):
}]
self
.
assertListEqual
(
expected_categories_list
,
categories
)
def
test_convert_label_map_to_categories_lvis_frequency_and_counts
(
self
):
label_map_proto
=
string_int_label_map_pb2
.
StringIntLabelMap
()
label_map_string
=
"""
item {
id:1
name:'person'
frequency: FREQUENT
instance_count: 1000
}
item {
id:2
name:'dog'
frequency: COMMON
instance_count: 100
}
item {
id:3
name:'cat'
frequency: RARE
instance_count: 10
}
"""
text_format
.
Parse
(
label_map_string
,
label_map_proto
)
categories
=
label_map_util
.
convert_label_map_to_categories
(
label_map_proto
,
max_num_classes
=
3
)
self
.
assertListEqual
([{
'id'
:
1
,
'name'
:
u
'person'
,
'frequency'
:
'f'
,
'instance_count'
:
1000
},
{
'id'
:
2
,
'name'
:
u
'dog'
,
'frequency'
:
'c'
,
'instance_count'
:
100
},
{
'id'
:
3
,
'name'
:
u
'cat'
,
'frequency'
:
'r'
,
'instance_count'
:
10
}],
categories
)
def
test_convert_label_map_to_categories
(
self
):
label_map_proto
=
self
.
_generate_label_map
(
num_classes
=
4
)
categories
=
label_map_util
.
convert_label_map_to_categories
(
label_map_proto
,
max_num_classes
=
3
)
expected_categories_list
=
[{
'name'
:
u
'1'
,
'id'
:
1
'id'
:
1
,
},
{
'name'
:
u
'2'
,
'id'
:
2
'id'
:
2
,
},
{
'name'
:
u
'3'
,
'id'
:
3
'id'
:
3
,
}]
self
.
assertListEqual
(
expected_categories_list
,
categories
)
...
...
@@ -259,7 +301,7 @@ class LabelMapUtilTest(tf.test.TestCase):
}
"""
label_map_proto
=
string_int_label_map_pb2
.
StringIntLabelMap
()
text_format
.
Merg
e
(
label_map_str
,
label_map_proto
)
text_format
.
Pars
e
(
label_map_str
,
label_map_proto
)
categories
=
label_map_util
.
convert_label_map_to_categories
(
label_map_proto
,
max_num_classes
=
1
)
self
.
assertEqual
(
'person'
,
categories
[
0
][
'name'
])
...
...
@@ -291,7 +333,7 @@ class LabelMapUtilTest(tf.test.TestCase):
}
"""
label_map_proto
=
string_int_label_map_pb2
.
StringIntLabelMap
()
text_format
.
Merg
e
(
label_map_str
,
label_map_proto
)
text_format
.
Pars
e
(
label_map_str
,
label_map_proto
)
with
self
.
assertRaises
(
ValueError
):
label_map_util
.
convert_label_map_to_categories
(
label_map_proto
,
max_num_classes
=
2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录