Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿飞的客栈
Mask_RCNN
提交
4a507188
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,发现更多精彩内容 >>
提交
4a507188
编写于
5月 15, 2018
作者:
J
Julien Rebetez
提交者:
Waleed
6月 05, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow configuration of FPN layers size and top-down pyramid size
上级
025f4c17
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
14 deletion
+24
-14
mrcnn/config.py
mrcnn/config.py
+6
-0
mrcnn/model.py
mrcnn/model.py
+18
-14
未找到文件。
mrcnn/config.py
浏览文件 @
4a507188
...
@@ -56,6 +56,12 @@ class Config(object):
...
@@ -56,6 +56,12 @@ class Config(object):
# are based on a Resnet101 backbone.
# are based on a Resnet101 backbone.
BACKBONE_STRIDES
=
[
4
,
8
,
16
,
32
,
64
]
BACKBONE_STRIDES
=
[
4
,
8
,
16
,
32
,
64
]
# Size of the fully-connected layers in the classification graph
FPN_CLASSIF_FC_LAYERS_SIZE
=
1024
# Size of the top-down layers used to build the feature pyramid
TOP_DOWN_PYRAMID_SIZE
=
256
# Number of classification classes (including background)
# Number of classification classes (including background)
NUM_CLASSES
=
1
# Override in sub-classes
NUM_CLASSES
=
1
# Override in sub-classes
...
...
mrcnn/model.py
浏览文件 @
4a507188
...
@@ -898,7 +898,8 @@ def build_rpn_model(anchor_stride, anchors_per_location, depth):
...
@@ -898,7 +898,8 @@ def build_rpn_model(anchor_stride, anchors_per_location, depth):
############################################################
############################################################
def
fpn_classifier_graph
(
rois
,
feature_maps
,
image_meta
,
def
fpn_classifier_graph
(
rois
,
feature_maps
,
image_meta
,
pool_size
,
num_classes
,
train_bn
=
True
):
pool_size
,
num_classes
,
train_bn
=
True
,
fc_layers_size
=
1024
):
"""Builds the computation graph of the feature pyramid network classifier
"""Builds the computation graph of the feature pyramid network classifier
and regressor heads.
and regressor heads.
...
@@ -910,6 +911,7 @@ def fpn_classifier_graph(rois, feature_maps, image_meta,
...
@@ -910,6 +911,7 @@ def fpn_classifier_graph(rois, feature_maps, image_meta,
pool_size: The width of the square feature map generated from ROI Pooling.
pool_size: The width of the square feature map generated from ROI Pooling.
num_classes: number of classes, which determines the depth of the results
num_classes: number of classes, which determines the depth of the results
train_bn: Boolean. Train or freeze Batch Norm layres
train_bn: Boolean. Train or freeze Batch Norm layres
fc_layers_size: Size of the 2 FC layers
Returns:
Returns:
logits: [N, NUM_CLASSES] classifier logits (before softmax)
logits: [N, NUM_CLASSES] classifier logits (before softmax)
...
@@ -922,11 +924,11 @@ def fpn_classifier_graph(rois, feature_maps, image_meta,
...
@@ -922,11 +924,11 @@ def fpn_classifier_graph(rois, feature_maps, image_meta,
x
=
PyramidROIAlign
([
pool_size
,
pool_size
],
x
=
PyramidROIAlign
([
pool_size
,
pool_size
],
name
=
"roi_align_classifier"
)([
rois
,
image_meta
]
+
feature_maps
)
name
=
"roi_align_classifier"
)([
rois
,
image_meta
]
+
feature_maps
)
# Two 1024 FC layers (implemented with Conv2D for consistency)
# Two 1024 FC layers (implemented with Conv2D for consistency)
x
=
KL
.
TimeDistributed
(
KL
.
Conv2D
(
1024
,
(
pool_size
,
pool_size
),
padding
=
"valid"
),
x
=
KL
.
TimeDistributed
(
KL
.
Conv2D
(
fc_layers_size
,
(
pool_size
,
pool_size
),
padding
=
"valid"
),
name
=
"mrcnn_class_conv1"
)(
x
)
name
=
"mrcnn_class_conv1"
)(
x
)
x
=
KL
.
TimeDistributed
(
BatchNorm
(),
name
=
'mrcnn_class_bn1'
)(
x
,
training
=
train_bn
)
x
=
KL
.
TimeDistributed
(
BatchNorm
(),
name
=
'mrcnn_class_bn1'
)(
x
,
training
=
train_bn
)
x
=
KL
.
Activation
(
'relu'
)(
x
)
x
=
KL
.
Activation
(
'relu'
)(
x
)
x
=
KL
.
TimeDistributed
(
KL
.
Conv2D
(
1024
,
(
1
,
1
)),
x
=
KL
.
TimeDistributed
(
KL
.
Conv2D
(
fc_layers_size
,
(
1
,
1
)),
name
=
"mrcnn_class_conv2"
)(
x
)
name
=
"mrcnn_class_conv2"
)(
x
)
x
=
KL
.
TimeDistributed
(
BatchNorm
(),
name
=
'mrcnn_class_bn2'
)(
x
,
training
=
train_bn
)
x
=
KL
.
TimeDistributed
(
BatchNorm
(),
name
=
'mrcnn_class_bn2'
)(
x
,
training
=
train_bn
)
x
=
KL
.
Activation
(
'relu'
)(
x
)
x
=
KL
.
Activation
(
'relu'
)(
x
)
...
@@ -1887,21 +1889,21 @@ class MaskRCNN():
...
@@ -1887,21 +1889,21 @@ class MaskRCNN():
stage5
=
True
,
train_bn
=
config
.
TRAIN_BN
)
stage5
=
True
,
train_bn
=
config
.
TRAIN_BN
)
# Top-down Layers
# Top-down Layers
# TODO: add assert to varify feature map sizes match what's in config
# TODO: add assert to varify feature map sizes match what's in config
P5
=
KL
.
Conv2D
(
256
,
(
1
,
1
),
name
=
'fpn_c5p5'
)(
C5
)
P5
=
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
1
,
1
),
name
=
'fpn_c5p5'
)(
C5
)
P4
=
KL
.
Add
(
name
=
"fpn_p4add"
)([
P4
=
KL
.
Add
(
name
=
"fpn_p4add"
)([
KL
.
UpSampling2D
(
size
=
(
2
,
2
),
name
=
"fpn_p5upsampled"
)(
P5
),
KL
.
UpSampling2D
(
size
=
(
2
,
2
),
name
=
"fpn_p5upsampled"
)(
P5
),
KL
.
Conv2D
(
256
,
(
1
,
1
),
name
=
'fpn_c4p4'
)(
C4
)])
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
1
,
1
),
name
=
'fpn_c4p4'
)(
C4
)])
P3
=
KL
.
Add
(
name
=
"fpn_p3add"
)([
P3
=
KL
.
Add
(
name
=
"fpn_p3add"
)([
KL
.
UpSampling2D
(
size
=
(
2
,
2
),
name
=
"fpn_p4upsampled"
)(
P4
),
KL
.
UpSampling2D
(
size
=
(
2
,
2
),
name
=
"fpn_p4upsampled"
)(
P4
),
KL
.
Conv2D
(
256
,
(
1
,
1
),
name
=
'fpn_c3p3'
)(
C3
)])
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
1
,
1
),
name
=
'fpn_c3p3'
)(
C3
)])
P2
=
KL
.
Add
(
name
=
"fpn_p2add"
)([
P2
=
KL
.
Add
(
name
=
"fpn_p2add"
)([
KL
.
UpSampling2D
(
size
=
(
2
,
2
),
name
=
"fpn_p3upsampled"
)(
P3
),
KL
.
UpSampling2D
(
size
=
(
2
,
2
),
name
=
"fpn_p3upsampled"
)(
P3
),
KL
.
Conv2D
(
256
,
(
1
,
1
),
name
=
'fpn_c2p2'
)(
C2
)])
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
1
,
1
),
name
=
'fpn_c2p2'
)(
C2
)])
# Attach 3x3 conv to all P layers to get the final feature maps.
# Attach 3x3 conv to all P layers to get the final feature maps.
P2
=
KL
.
Conv2D
(
256
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p2"
)(
P2
)
P2
=
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p2"
)(
P2
)
P3
=
KL
.
Conv2D
(
256
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p3"
)(
P3
)
P3
=
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p3"
)(
P3
)
P4
=
KL
.
Conv2D
(
256
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p4"
)(
P4
)
P4
=
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p4"
)(
P4
)
P5
=
KL
.
Conv2D
(
256
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p5"
)(
P5
)
P5
=
KL
.
Conv2D
(
config
.
TOP_DOWN_PYRAMID_SIZE
,
(
3
,
3
),
padding
=
"SAME"
,
name
=
"fpn_p5"
)(
P5
)
# P6 is used for the 5th anchor scale in RPN. Generated by
# P6 is used for the 5th anchor scale in RPN. Generated by
# subsampling from P5 with stride of 2.
# subsampling from P5 with stride of 2.
P6
=
KL
.
MaxPooling2D
(
pool_size
=
(
1
,
1
),
strides
=
2
,
name
=
"fpn_p6"
)(
P5
)
P6
=
KL
.
MaxPooling2D
(
pool_size
=
(
1
,
1
),
strides
=
2
,
name
=
"fpn_p6"
)(
P5
)
...
@@ -1923,7 +1925,7 @@ class MaskRCNN():
...
@@ -1923,7 +1925,7 @@ class MaskRCNN():
# RPN Model
# RPN Model
rpn
=
build_rpn_model
(
config
.
RPN_ANCHOR_STRIDE
,
rpn
=
build_rpn_model
(
config
.
RPN_ANCHOR_STRIDE
,
len
(
config
.
RPN_ANCHOR_RATIOS
),
256
)
len
(
config
.
RPN_ANCHOR_RATIOS
),
config
.
TOP_DOWN_PYRAMID_SIZE
)
# Loop through pyramid layers
# Loop through pyramid layers
layer_outputs
=
[]
# list of lists
layer_outputs
=
[]
# list of lists
for
p
in
rpn_feature_maps
:
for
p
in
rpn_feature_maps
:
...
@@ -1980,7 +1982,8 @@ class MaskRCNN():
...
@@ -1980,7 +1982,8 @@ class MaskRCNN():
mrcnn_class_logits
,
mrcnn_class
,
mrcnn_bbox
=
\
mrcnn_class_logits
,
mrcnn_class
,
mrcnn_bbox
=
\
fpn_classifier_graph
(
rois
,
mrcnn_feature_maps
,
input_image_meta
,
fpn_classifier_graph
(
rois
,
mrcnn_feature_maps
,
input_image_meta
,
config
.
POOL_SIZE
,
config
.
NUM_CLASSES
,
config
.
POOL_SIZE
,
config
.
NUM_CLASSES
,
train_bn
=
config
.
TRAIN_BN
)
train_bn
=
config
.
TRAIN_BN
,
fc_layers_size
=
config
.
FPN_CLASSIF_FC_LAYERS_SIZE
)
mrcnn_mask
=
build_fpn_mask_graph
(
rois
,
mrcnn_feature_maps
,
mrcnn_mask
=
build_fpn_mask_graph
(
rois
,
mrcnn_feature_maps
,
input_image_meta
,
input_image_meta
,
...
@@ -2019,7 +2022,8 @@ class MaskRCNN():
...
@@ -2019,7 +2022,8 @@ class MaskRCNN():
mrcnn_class_logits
,
mrcnn_class
,
mrcnn_bbox
=
\
mrcnn_class_logits
,
mrcnn_class
,
mrcnn_bbox
=
\
fpn_classifier_graph
(
rpn_rois
,
mrcnn_feature_maps
,
input_image_meta
,
fpn_classifier_graph
(
rpn_rois
,
mrcnn_feature_maps
,
input_image_meta
,
config
.
POOL_SIZE
,
config
.
NUM_CLASSES
,
config
.
POOL_SIZE
,
config
.
NUM_CLASSES
,
train_bn
=
config
.
TRAIN_BN
)
train_bn
=
config
.
TRAIN_BN
,
fc_layers_size
=
config
.
FPN_CLASSIF_FC_LAYERS_SIZE
)
# Detections
# Detections
# output is [batch, num_detections, (y1, x1, y2, x2, class_id, score)] in
# output is [batch, num_detections, (y1, x1, y2, x2, class_id, score)] in
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录