未验证 提交 1f82ad23 编写于 作者: G Guanghua Yu 提交者: GitHub

fix solov2 with_background & from_config (#2211)

上级 3a77e318
...@@ -9,7 +9,6 @@ SOLOv2: ...@@ -9,7 +9,6 @@ SOLOv2:
mask_head: SOLOv2MaskHead mask_head: SOLOv2MaskHead
ResNet: ResNet:
# index 0 stands for res2
depth: 50 depth: 50
norm_type: bn norm_type: bn
freeze_at: 0 freeze_at: 0
...@@ -17,11 +16,7 @@ ResNet: ...@@ -17,11 +16,7 @@ ResNet:
num_stages: 4 num_stages: 4
FPN: FPN:
in_channels: [256, 512, 1024, 2048]
out_channel: 256 out_channel: 256
min_level: 0
max_level: 4
spatial_scale: [0.25, 0.125, 0.0625, 0.03125]
SOLOv2Head: SOLOv2Head:
seg_feat_channels: 512 seg_feat_channels: 512
...@@ -32,7 +27,6 @@ SOLOv2Head: ...@@ -32,7 +27,6 @@ SOLOv2Head:
mask_nms: MaskMatrixNMS mask_nms: MaskMatrixNMS
SOLOv2MaskHead: SOLOv2MaskHead:
in_channels: 256
mid_channels: 128 mid_channels: 128
out_channels: 256 out_channels: 256
start_level: 0 start_level: 0
......
...@@ -644,7 +644,7 @@ class Gt2Solov2TargetOp(BaseOperator): ...@@ -644,7 +644,7 @@ class Gt2Solov2TargetOp(BaseOperator):
max_ins_num = [0] * len(self.num_grids) max_ins_num = [0] * len(self.num_grids)
for sample in samples: for sample in samples:
gt_bboxes_raw = sample['gt_bbox'] gt_bboxes_raw = sample['gt_bbox']
gt_labels_raw = sample['gt_class'] gt_labels_raw = sample['gt_class'] + 1
im_c, im_h, im_w = sample['image'].shape[:] im_c, im_h, im_w = sample['image'].shape[:]
gt_masks_raw = sample['gt_segm'].astype(np.uint8) gt_masks_raw = sample['gt_segm'].astype(np.uint8)
mask_feat_size = [ mask_feat_size = [
......
...@@ -18,7 +18,7 @@ from __future__ import print_function ...@@ -18,7 +18,7 @@ from __future__ import print_function
import paddle import paddle
from ppdet.core.workspace import register from ppdet.core.workspace import register, create
from .meta_arch import BaseArch from .meta_arch import BaseArch
__all__ = ['SOLOv2'] __all__ = ['SOLOv2']
...@@ -37,7 +37,6 @@ class SOLOv2(BaseArch): ...@@ -37,7 +37,6 @@ class SOLOv2(BaseArch):
""" """
__category__ = 'architecture' __category__ = 'architecture'
__inject__ = ['backbone', 'neck', 'solov2_head', 'mask_head']
def __init__(self, backbone, solov2_head, mask_head, neck=None): def __init__(self, backbone, solov2_head, mask_head, neck=None):
super(SOLOv2, self).__init__() super(SOLOv2, self).__init__()
...@@ -46,11 +45,28 @@ class SOLOv2(BaseArch): ...@@ -46,11 +45,28 @@ class SOLOv2(BaseArch):
self.solov2_head = solov2_head self.solov2_head = solov2_head
self.mask_head = mask_head self.mask_head = mask_head
@classmethod
def from_config(cls, cfg, *args, **kwargs):
backbone = create(cfg['backbone'])
kwargs = {'input_shape': backbone.out_shape}
neck = create(cfg['neck'], **kwargs)
kwargs = {'input_shape': neck.out_shape}
solov2_head = create(cfg['solov2_head'], **kwargs)
mask_head = create(cfg['mask_head'], **kwargs)
return {
'backbone': backbone,
'neck': neck,
'solov2_head': solov2_head,
'mask_head': mask_head,
}
def model_arch(self): def model_arch(self):
body_feats = self.backbone(self.inputs) body_feats = self.backbone(self.inputs)
if self.neck is not None: body_feats = self.neck(body_feats)
body_feats, spatial_scale = self.neck(body_feats)
self.seg_pred = self.mask_head(body_feats) self.seg_pred = self.mask_head(body_feats)
......
...@@ -190,7 +190,7 @@ class SOLOv2Head(nn.Layer): ...@@ -190,7 +190,7 @@ class SOLOv2Head(nn.Layer):
self.num_classes = num_classes self.num_classes = num_classes
self.in_channels = in_channels self.in_channels = in_channels
self.seg_num_grids = num_grids self.seg_num_grids = num_grids
self.cate_out_channels = self.num_classes - 1 self.cate_out_channels = self.num_classes
self.seg_feat_channels = seg_feat_channels self.seg_feat_channels = seg_feat_channels
self.stacked_convs = stacked_convs self.stacked_convs = stacked_convs
self.kernel_out_channels = kernel_out_channels self.kernel_out_channels = kernel_out_channels
......
...@@ -87,7 +87,7 @@ def get_solov2_segm_res(results, image_id, num_id_to_cat_id_map): ...@@ -87,7 +87,7 @@ def get_solov2_segm_res(results, image_id, num_id_to_cat_id_map):
return None return None
# for each sample # for each sample
for i in range(lengths - 1): for i in range(lengths - 1):
clsid = int(clsid_labels[i]) + 1 clsid = int(clsid_labels[i])
catid = num_id_to_cat_id_map[clsid] catid = num_id_to_cat_id_map[clsid]
score = float(clsid_scores[i]) score = float(clsid_scores[i])
mask = segms[i] mask = segms[i]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册