Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
dc9f89fb
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,发现更多精彩内容 >>
提交
dc9f89fb
编写于
9月 10, 2020
作者:
Z
Zhenyu Tan
提交者:
A. Unique TensorFlower
9月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Internal change
PiperOrigin-RevId: 331045692
上级
55d41fd6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
125 addition
and
6 deletion
+125
-6
official/vision/beta/ops/anchor.py
official/vision/beta/ops/anchor.py
+2
-2
official/vision/detection/dataloader/anchor.py
official/vision/detection/dataloader/anchor.py
+2
-2
official/vision/detection/utils/object_detection/target_assigner.py
...ision/detection/utils/object_detection/target_assigner.py
+2
-2
official/vision/keras_cv/__init__.py
official/vision/keras_cv/__init__.py
+1
-0
official/vision/keras_cv/ops/__init__.py
official/vision/keras_cv/ops/__init__.py
+16
-0
official/vision/keras_cv/ops/iou_similarity.py
official/vision/keras_cv/ops/iou_similarity.py
+102
-0
未找到文件。
official/vision/beta/ops/anchor.py
浏览文件 @
dc9f89fb
...
...
@@ -17,12 +17,12 @@
import
collections
# Import libraries
import
tensorflow
as
tf
from
official.vision
import
keras_cv
from
official.vision.beta.ops.experimental
import
anchor_generator
from
official.vision.detection.utils.object_detection
import
argmax_matcher
from
official.vision.detection.utils.object_detection
import
balanced_positive_negative_sampler
from
official.vision.detection.utils.object_detection
import
box_list
from
official.vision.detection.utils.object_detection
import
faster_rcnn_box_coder
from
official.vision.detection.utils.object_detection
import
region_similarity_calculator
from
official.vision.detection.utils.object_detection
import
target_assigner
...
...
@@ -135,7 +135,7 @@ class AnchorLabeler(object):
upper-bound threshold to assign negative labels for anchors. An anchor
with a score below the threshold is labeled negative.
"""
similarity_calc
=
region_similarity_calculator
.
IouSimilarity
()
similarity_calc
=
keras_cv
.
ops
.
IouSimilarity
()
matcher
=
argmax_matcher
.
ArgMaxMatcher
(
match_threshold
,
unmatched_threshold
=
unmatched_threshold
,
...
...
official/vision/detection/dataloader/anchor.py
浏览文件 @
dc9f89fb
...
...
@@ -21,11 +21,11 @@ from __future__ import print_function
import
collections
import
tensorflow
as
tf
from
official.vision
import
keras_cv
from
official.vision.detection.utils.object_detection
import
argmax_matcher
from
official.vision.detection.utils.object_detection
import
balanced_positive_negative_sampler
from
official.vision.detection.utils.object_detection
import
box_list
from
official.vision.detection.utils.object_detection
import
faster_rcnn_box_coder
from
official.vision.detection.utils.object_detection
import
region_similarity_calculator
from
official.vision.detection.utils.object_detection
import
target_assigner
...
...
@@ -134,7 +134,7 @@ class AnchorLabeler(object):
upper-bound threshold to assign negative labels for anchors. An anchor
with a score below the threshold is labeled negative.
"""
similarity_calc
=
region_similarity_calculator
.
IouSimilarity
()
similarity_calc
=
keras_cv
.
ops
.
IouSimilarity
()
matcher
=
argmax_matcher
.
ArgMaxMatcher
(
match_threshold
,
unmatched_threshold
=
unmatched_threshold
,
...
...
official/vision/detection/utils/object_detection/target_assigner.py
浏览文件 @
dc9f89fb
...
...
@@ -151,8 +151,8 @@ class TargetAssigner(object):
groundtruth_weights
=
tf
.
ones
([
num_gt_boxes
],
dtype
=
tf
.
float32
)
with
tf
.
control_dependencies
(
[
unmatched_shape_assert
,
labels_and_box_shapes_assert
]):
match_quality_matrix
=
self
.
_similarity_calc
.
compare
(
groundtruth_boxes
,
anchors
)
match_quality_matrix
=
self
.
_similarity_calc
(
groundtruth_boxes
.
get
(),
anchors
.
get
()
)
match
=
self
.
_matcher
.
match
(
match_quality_matrix
,
**
params
)
reg_targets
=
self
.
_create_regression_targets
(
anchors
,
groundtruth_boxes
,
match
)
...
...
official/vision/keras_cv/__init__.py
浏览文件 @
dc9f89fb
...
...
@@ -15,3 +15,4 @@
"""Keras-NLP package definition."""
# pylint: disable=wildcard-import
from
official.vision.keras_cv.losses
import
*
from
official.vision.keras_cv.ops
import
*
official/vision/keras_cv/ops/__init__.py
0 → 100644
浏览文件 @
dc9f89fb
# Copyright 2020 The TensorFlow 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.
# ==============================================================================
"""Keras-CV layers package definition."""
from
official.vision.keras_cv.ops.iou_similarity
import
IouSimilarity
official/vision/keras_cv/ops/iou_similarity.py
0 → 100644
浏览文件 @
dc9f89fb
# Copyright 2020 The TensorFlow 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.
# ==============================================================================
"""Region Similarity Calculators."""
import
tensorflow
as
tf
def
area
(
box
):
"""Computes area of boxes.
Args:
box: a float Tensor with [N, 4].
Returns:
a float tensor with [N].
"""
with
tf
.
name_scope
(
'Area'
):
y_min
,
x_min
,
y_max
,
x_max
=
tf
.
split
(
value
=
box
,
num_or_size_splits
=
4
,
axis
=
1
)
return
tf
.
squeeze
((
y_max
-
y_min
)
*
(
x_max
-
x_min
),
[
1
])
def
intersection
(
box1
,
box2
):
"""Compute pairwise intersection areas between boxes.
Args:
box1: a float Tensor with [N, 4].
box2: a float Tensor with [M, 4].
Returns:
a float tensor with shape [N, M] representing pairwise intersections
"""
with
tf
.
name_scope
(
'Intersection'
):
y_min1
,
x_min1
,
y_max1
,
x_max1
=
tf
.
split
(
value
=
box1
,
num_or_size_splits
=
4
,
axis
=
1
)
y_min2
,
x_min2
,
y_max2
,
x_max2
=
tf
.
split
(
value
=
box2
,
num_or_size_splits
=
4
,
axis
=
1
)
y_min_max
=
tf
.
minimum
(
y_max1
,
tf
.
transpose
(
a
=
y_max2
))
y_max_min
=
tf
.
maximum
(
y_min1
,
tf
.
transpose
(
a
=
y_min2
))
intersect_heights
=
tf
.
maximum
(
0.0
,
y_min_max
-
y_max_min
)
x_min_max
=
tf
.
minimum
(
x_max1
,
tf
.
transpose
(
a
=
x_max2
))
x_max_min
=
tf
.
maximum
(
x_min1
,
tf
.
transpose
(
a
=
x_min2
))
intersect_widths
=
tf
.
maximum
(
0.0
,
x_min_max
-
x_max_min
)
return
intersect_heights
*
intersect_widths
def
iou
(
box1
,
box2
):
"""Computes pairwise intersection-over-union between box collections.
Args:
box1: a float Tensor with [N, 4].
box2: a float Tensor with [M, 4].
Returns:
a tensor with shape [N, M] representing pairwise iou scores.
"""
intersections
=
intersection
(
box1
,
box2
)
areas1
=
area
(
box1
)
areas2
=
area
(
box2
)
unions
=
(
tf
.
expand_dims
(
areas1
,
1
)
+
tf
.
expand_dims
(
areas2
,
0
)
-
intersections
)
return
tf
.
where
(
tf
.
equal
(
intersections
,
0.0
),
tf
.
zeros_like
(
intersections
),
tf
.
truediv
(
intersections
,
unions
))
class
IouSimilarity
():
"""Class to compute similarity based on Intersection over Union (IOU) metric.
"""
def
__call__
(
self
,
groundtruth_boxes
,
anchors
):
"""Compute pairwise IOU similarity between ground truth boxes and anchors.
Args:
groundtruth_boxes: a float Tensor with N boxes.
anchors: a float Tensor with M boxes.
Returns:
A tensor with shape [N, M] representing pairwise iou scores.
Input shape:
groundtruth_boxes: [N, 4]
anchors: [M, 4]
Output shape:
[N, M]
"""
with
tf
.
name_scope
(
'IOU'
):
return
iou
(
groundtruth_boxes
,
anchors
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录