Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
38e48f91
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,发现更多精彩内容 >>
提交
38e48f91
编写于
12月 10, 2019
作者:
P
Pengchong Jin
提交者:
A. Unique TensorFlower
12月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A more accurate implementation of mask pasting.
PiperOrigin-RevId: 284854952
上级
68104ce3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
86 addition
and
0 deletion
+86
-0
official/vision/detection/utils/mask_utils.py
official/vision/detection/utils/mask_utils.py
+86
-0
未找到文件。
official/vision/detection/utils/mask_utils.py
浏览文件 @
38e48f91
...
...
@@ -17,6 +17,7 @@ from __future__ import absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
math
import
numpy
as
np
import
cv2
...
...
@@ -104,3 +105,88 @@ def paste_instance_masks(masks,
assert
masks
.
shape
[
0
]
==
segms
.
shape
[
0
]
return
segms
def
paste_instance_masks_v2
(
masks
,
detected_boxes
,
image_height
,
image_width
):
"""Paste instance masks to generate the image segmentation (v2).
Args:
masks: a numpy array of shape [N, mask_height, mask_width] representing the
instance masks w.r.t. the `detected_boxes`.
detected_boxes: a numpy array of shape [N, 4] representing the reference
bounding boxes.
image_height: an integer representing the height of the image.
image_width: an integer representing the width of the image.
Returns:
segms: a numpy array of shape [N, image_height, image_width] representing
the instance masks *pasted* on the image canvas.
"""
_
,
mask_height
,
mask_width
=
masks
.
shape
segms
=
[]
for
i
,
mask
in
enumerate
(
masks
):
box
=
detected_boxes
[
i
,
:]
xmin
=
box
[
0
]
ymin
=
box
[
1
]
xmax
=
xmin
+
box
[
2
]
ymax
=
ymin
+
box
[
3
]
# Sample points of the cropped mask w.r.t. the image grid.
# Note that these coordinates may fall beyond the image.
# Pixel clipping will happen after warping.
xmin_int
=
int
(
math
.
floor
(
xmin
))
xmax_int
=
int
(
math
.
ceil
(
xmax
))
ymin_int
=
int
(
math
.
floor
(
ymin
))
ymax_int
=
int
(
math
.
ceil
(
ymax
))
alpha
=
box
[
2
]
/
(
1.0
*
mask_width
)
beta
=
box
[
3
]
/
(
1.0
*
mask_height
)
# pylint: disable=invalid-name
# Transformation from mask pixel indices to image coordinate.
M_mask_to_image
=
np
.
array
(
[[
alpha
,
0
,
xmin
],
[
0
,
beta
,
ymin
],
[
0
,
0
,
1
]],
dtype
=
np
.
float32
)
# Transformation from image to cropped mask coordinate.
M_image_to_crop
=
np
.
array
(
[[
1
,
0
,
-
xmin_int
],
[
0
,
1
,
-
ymin_int
],
[
0
,
0
,
1
]],
dtype
=
np
.
float32
)
M
=
np
.
dot
(
M_image_to_crop
,
M_mask_to_image
)
# Compensate the half pixel offset that OpenCV has in the
# warpPerspective implementation: the top-left pixel is sampled
# at (0,0), but we want it to be at (0.5, 0.5).
M
=
np
.
dot
(
np
.
dot
(
np
.
array
([[
1
,
0
,
-
0.5
],
[
0
,
1
,
-
0.5
],
[
0
,
0
,
1
]],
np
.
float32
),
M
),
np
.
array
([[
1
,
0
,
0.5
],
[
0
,
1
,
0.5
],
[
0
,
0
,
1
]],
np
.
float32
))
# pylint: enable=invalid-name
cropped_mask
=
cv2
.
warpPerspective
(
mask
.
astype
(
np
.
float32
),
M
,
(
xmax_int
-
xmin_int
,
ymax_int
-
ymin_int
))
cropped_mask
=
np
.
array
(
cropped_mask
>
0.5
,
dtype
=
np
.
uint8
)
img_mask
=
np
.
zeros
((
image_height
,
image_width
))
x0
=
max
(
min
(
xmin_int
,
image_width
),
0
)
x1
=
max
(
min
(
xmax_int
,
image_width
),
0
)
y0
=
max
(
min
(
ymin_int
,
image_height
),
0
)
y1
=
max
(
min
(
ymax_int
,
image_height
),
0
)
img_mask
[
y0
:
y1
,
x0
:
x1
]
=
cropped_mask
[
(
y0
-
ymin_int
):(
y1
-
ymin_int
),
(
x0
-
xmin_int
):(
x1
-
xmin_int
)]
segms
.
append
(
img_mask
)
segms
=
np
.
array
(
segms
)
return
segms
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录