Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿飞的客栈
Mask_RCNN
提交
66b02824
M
Mask_RCNN
项目概览
阿飞的客栈
/
Mask_RCNN
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mask_RCNN
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
66b02824
编写于
11月 15, 2017
作者:
G
Gyuri Im
提交者:
Waleed
11月 17, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
conform to pep8
上级
7c1b37d0
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
292 addition
and
218 deletion
+292
-218
coco.py
coco.py
+1
-1
model.py
model.py
+264
-195
parallel_model.py
parallel_model.py
+1
-1
shapes.py
shapes.py
+14
-11
utils.py
utils.py
+7
-5
visualize.py
visualize.py
+5
-5
未找到文件。
coco.py
浏览文件 @
66b02824
...
...
@@ -134,7 +134,7 @@ class CocoDataset(utils.Dataset):
path
=
os
.
path
.
join
(
image_dir
,
coco
.
imgs
[
i
][
'file_name'
]),
width
=
coco
.
imgs
[
i
][
"width"
],
height
=
coco
.
imgs
[
i
][
"height"
],
annotations
=
coco
.
loadAnns
(
coco
.
getAnnIds
(
imgIds
=
[
i
],
catIds
=
class_ids
,
iscrowd
=
False
)))
annotations
=
coco
.
loadAnns
(
coco
.
getAnnIds
(
imgIds
=
[
i
],
catIds
=
class_ids
,
iscrowd
=
False
)))
if
return_coco
:
return
coco
...
...
model.py
浏览文件 @
66b02824
此差异已折叠。
点击以展开。
parallel_model.py
浏览文件 @
66b02824
...
...
@@ -75,7 +75,7 @@ class ParallelModel(KM.Model):
self
.
inner_model
.
inputs
)
inputs
=
[
KL
.
Lambda
(
lambda
s
:
input_slices
[
name
][
i
],
output_shape
=
lambda
s
:
(
None
,)
+
s
[
1
:])(
tensor
)
output_shape
=
lambda
s
:
(
None
,)
+
s
[
1
:])(
tensor
)
for
name
,
tensor
in
zipped_inputs
]
# Create the model replica and get the outputs
outputs
=
self
.
inner_model
(
inputs
)
...
...
shapes.py
浏览文件 @
66b02824
...
...
@@ -109,13 +109,14 @@ class ShapesDataset(utils.Dataset):
count
=
len
(
shapes
)
mask
=
np
.
zeros
([
info
[
'height'
],
info
[
'width'
],
count
],
dtype
=
np
.
uint8
)
for
i
,
(
shape
,
_
,
dims
)
in
enumerate
(
info
[
'shapes'
]):
mask
[:,
:,
i
:
i
+
1
]
=
self
.
draw_shape
(
mask
[:,
:,
i
:
i
+
1
].
copy
(),
shape
,
dims
,
1
)
mask
[:,
:,
i
:
i
+
1
]
=
self
.
draw_shape
(
mask
[:,
:,
i
:
i
+
1
].
copy
(),
shape
,
dims
,
1
)
# Handle occlusions
occlusion
=
np
.
logical_not
(
mask
[:,
:,
-
1
]).
astype
(
np
.
uint8
)
for
i
in
range
(
count
-
2
,
-
1
,
-
1
):
for
i
in
range
(
count
-
2
,
-
1
,
-
1
):
mask
[:,
:,
i
]
=
mask
[:,
:,
i
]
*
occlusion
occlusion
=
np
.
logical_and
(
occlusion
,
np
.
logical_not
(
mask
[:,
:,
i
]))
occlusion
=
np
.
logical_and
(
occlusion
,
np
.
logical_not
(
mask
[:,
:,
i
]))
# Map class names to class IDs.
class_ids
=
np
.
array
([
self
.
class_names
.
index
(
s
[
0
])
for
s
in
shapes
])
return
mask
,
class_ids
.
astype
(
np
.
int32
)
...
...
@@ -125,13 +126,14 @@ class ShapesDataset(utils.Dataset):
# Get the center x, y and the size s
x
,
y
,
s
=
dims
if
shape
==
'square'
:
image
=
cv2
.
rectangle
(
image
,
(
x
-
s
,
y
-
s
),
(
x
+
s
,
y
+
s
),
color
,
-
1
)
image
=
cv2
.
rectangle
(
image
,
(
x
-
s
,
y
-
s
),
(
x
+
s
,
y
+
s
),
color
,
-
1
)
elif
shape
==
"circle"
:
image
=
cv2
.
circle
(
image
,
(
x
,
y
),
s
,
color
,
-
1
)
elif
shape
==
"triangle"
:
points
=
np
.
array
([[(
x
,
y
-
s
),
(
x
-
s
/
math
.
sin
(
math
.
radians
(
60
)),
y
+
s
),
(
x
+
s
/
math
.
sin
(
math
.
radians
(
60
)),
y
+
s
),
points
=
np
.
array
([[(
x
,
y
-
s
),
(
x
-
s
/
math
.
sin
(
math
.
radians
(
60
)),
y
+
s
),
(
x
+
s
/
math
.
sin
(
math
.
radians
(
60
)),
y
+
s
),
]],
dtype
=
np
.
int32
)
image
=
cv2
.
fillPoly
(
image
,
points
,
color
)
return
image
...
...
@@ -154,7 +156,7 @@ class ShapesDataset(utils.Dataset):
y
=
random
.
randint
(
buffer
,
height
-
buffer
-
1
)
x
=
random
.
randint
(
buffer
,
width
-
buffer
-
1
)
# Size
s
=
random
.
randint
(
buffer
,
height
//
4
)
s
=
random
.
randint
(
buffer
,
height
//
4
)
return
shape
,
color
,
(
x
,
y
,
s
)
def
random_image
(
self
,
height
,
width
):
...
...
@@ -173,9 +175,10 @@ class ShapesDataset(utils.Dataset):
shape
,
color
,
dims
=
self
.
random_shape
(
height
,
width
)
shapes
.
append
((
shape
,
color
,
dims
))
x
,
y
,
s
=
dims
boxes
.
append
([
y
-
s
,
x
-
s
,
y
+
s
,
x
+
s
])
boxes
.
append
([
y
-
s
,
x
-
s
,
y
+
s
,
x
+
s
])
# Apply non-max suppression wit 0.3 threshold to avoid
# shapes covering each other
keep_ixs
=
utils
.
non_max_suppression
(
np
.
array
(
boxes
),
np
.
arange
(
N
),
0.3
)
keep_ixs
=
utils
.
non_max_suppression
(
np
.
array
(
boxes
),
np
.
arange
(
N
),
0.3
)
shapes
=
[
s
for
i
,
s
in
enumerate
(
shapes
)
if
i
in
keep_ixs
]
return
bg_color
,
shapes
utils.py
浏览文件 @
66b02824
...
...
@@ -220,6 +220,7 @@ class Dataset(object):
See COCODataset and ShapesDataset as examples.
"""
def
__init__
(
self
,
class_map
=
None
):
self
.
_image_ids
=
[]
self
.
image_info
=
[]
...
...
@@ -294,7 +295,7 @@ class Dataset(object):
def
map_source_class_id
(
self
,
source_class_id
):
"""Takes a source class ID and returns the int class ID assigned to it.
For example:
For example:
dataset.map_source_class_id("coco.12") -> 23
"""
return
self
.
class_from_source_map
[
source_class_id
]
...
...
@@ -606,7 +607,7 @@ def compute_ap(gt_boxes, gt_class_ids,
break
# Compute precision and recall at each prediction box step
precisions
=
np
.
cumsum
(
pred_match
)
/
(
np
.
arange
(
len
(
pred_match
))
+
1
)
precisions
=
np
.
cumsum
(
pred_match
)
/
(
np
.
arange
(
len
(
pred_match
))
+
1
)
recalls
=
np
.
cumsum
(
pred_match
).
astype
(
np
.
float32
)
/
len
(
gt_match
)
# Pad with start and end values to simplify the math
...
...
@@ -616,12 +617,13 @@ def compute_ap(gt_boxes, gt_class_ids,
# Ensure precision values decrease but don't increase. This way, the
# precision value at each recall threshold is the maximum it can be
# for all following recall thresholds, as specified by the VOC paper.
for
i
in
range
(
len
(
precisions
)
-
2
,
-
1
,
-
1
):
precisions
[
i
]
=
np
.
maximum
(
precisions
[
i
],
precisions
[
i
+
1
])
for
i
in
range
(
len
(
precisions
)
-
2
,
-
1
,
-
1
):
precisions
[
i
]
=
np
.
maximum
(
precisions
[
i
],
precisions
[
i
+
1
])
# Compute mean AP over recall range
indices
=
np
.
where
(
recalls
[:
-
1
]
!=
recalls
[
1
:])[
0
]
+
1
mAP
=
np
.
sum
((
recalls
[
indices
]
-
recalls
[
indices
-
1
])
*
precisions
[
indices
])
mAP
=
np
.
sum
((
recalls
[
indices
]
-
recalls
[
indices
-
1
])
*
precisions
[
indices
])
return
mAP
,
precisions
,
recalls
,
overlaps
...
...
visualize.py
浏览文件 @
66b02824
...
...
@@ -194,7 +194,7 @@ def draw_rois(image, rois, refined_rois, mask, class_ids, class_names, limit=10)
# Mask
m
=
utils
.
unmold_mask
(
mask
[
id
],
rois
[
id
]
[:
4
].
astype
(
np
.
int32
),
image
.
shape
)
[:
4
].
astype
(
np
.
int32
),
image
.
shape
)
masked_image
=
apply_mask
(
masked_image
,
m
,
color
)
ax
.
imshow
(
masked_image
)
...
...
@@ -236,10 +236,10 @@ def display_top_masks(image, mask, class_ids, class_names, limit=4):
class_id
=
top_ids
[
i
]
if
i
<
len
(
top_ids
)
else
-
1
# Pull masks of instances belonging to the same class.
m
=
mask
[:,
:,
np
.
where
(
class_ids
==
class_id
)[
0
]]
m
=
np
.
sum
(
m
*
np
.
arange
(
1
,
m
.
shape
[
-
1
]
+
1
),
-
1
)
m
=
np
.
sum
(
m
*
np
.
arange
(
1
,
m
.
shape
[
-
1
]
+
1
),
-
1
)
to_display
.
append
(
m
)
titles
.
append
(
class_names
[
class_id
]
if
class_id
!=
-
1
else
"-"
)
display_images
(
to_display
,
titles
=
titles
,
cols
=
limit
+
1
,
cmap
=
"Blues_r"
)
display_images
(
to_display
,
titles
=
titles
,
cols
=
limit
+
1
,
cmap
=
"Blues_r"
)
def
plot_precision_recall
(
AP
,
precisions
,
recalls
):
...
...
@@ -362,7 +362,7 @@ def draw_boxes(image, boxes=None, refined_boxes=None,
# Refined boxes
if
refined_boxes
is
not
None
and
visibility
>
0
:
ry1
,
rx1
,
ry2
,
rx2
=
refined_boxes
[
i
].
astype
(
np
.
int32
)
p
=
patches
.
Rectangle
((
rx1
,
ry1
),
rx2
-
rx1
,
ry2
-
ry1
,
linewidth
=
2
,
p
=
patches
.
Rectangle
((
rx1
,
ry1
),
rx2
-
rx1
,
ry2
-
ry1
,
linewidth
=
2
,
edgecolor
=
color
,
facecolor
=
'none'
)
ax
.
add_patch
(
p
)
# Connect the top-left corners of the anchor and proposal
...
...
@@ -378,7 +378,7 @@ def draw_boxes(image, boxes=None, refined_boxes=None,
x
=
random
.
randint
(
x1
,
(
x1
+
x2
)
//
2
)
ax
.
text
(
x1
,
y1
,
caption
,
size
=
11
,
verticalalignment
=
'top'
,
color
=
'w'
,
backgroundcolor
=
"none"
,
bbox
=
{
'facecolor'
:
color
,
'alpha'
:
0.5
,
bbox
=
{
'facecolor'
:
color
,
'alpha'
:
0.5
,
'pad'
:
2
,
'edgecolor'
:
'none'
})
# Masks
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录