提交 f8b2d8a4 编写于 作者: Y Yuan Gao 提交者: wangguanzhong

standard SENet and add a warning in coco loader (#3047)

* standard SENet and add a warning in coco loader
上级 f8b4dfed
...@@ -83,6 +83,10 @@ def load(anno_path, sample_num=-1, with_background=True): ...@@ -83,6 +83,10 @@ def load(anno_path, sample_num=-1, with_background=True):
if inst['area'] > 0 and x2 >= x1 and y2 >= y1: if inst['area'] > 0 and x2 >= x1 and y2 >= y1:
inst['clean_bbox'] = [x1, y1, x2, y2] inst['clean_bbox'] = [x1, y1, x2, y2]
bboxes.append(inst) bboxes.append(inst)
else:
logger.warn(
'Found an invalid bbox in annotations: im_id: {}, area: {} x: {}, y: {}, h: {}, w: {}.'.
format(img_id, float(inst['area']), x, y, box_w, box_h))
num_bbox = len(bboxes) num_bbox = len(bboxes)
gt_bbox = np.zeros((num_bbox, 4), dtype=np.float32) gt_bbox = np.zeros((num_bbox, 4), dtype=np.float32)
......
...@@ -89,9 +89,16 @@ class ResNet(object): ...@@ -89,9 +89,16 @@ class ResNet(object):
self._c1_out_chan_num = 64 self._c1_out_chan_num = 64
self.na = NameAdapter(self) self.na = NameAdapter(self)
def _conv_offset(self, input, filter_size, stride, padding, act=None, name=None): def _conv_offset(self,
input,
filter_size,
stride,
padding,
act=None,
name=None):
out_channel = filter_size * filter_size * 3 out_channel = filter_size * filter_size * 3
out = fluid.layers.conv2d(input, out = fluid.layers.conv2d(
input,
num_filters=out_channel, num_filters=out_channel,
filter_size=filter_size, filter_size=filter_size,
stride=stride, stride=stride,
...@@ -132,8 +139,8 @@ class ResNet(object): ...@@ -132,8 +139,8 @@ class ResNet(object):
padding=(filter_size - 1) // 2, padding=(filter_size - 1) // 2,
act=None, act=None,
name=name + "_conv_offset") name=name + "_conv_offset")
offset_channel = filter_size ** 2 * 2 offset_channel = filter_size**2 * 2
mask_channel = filter_size ** 2 mask_channel = filter_size**2
offset, mask = fluid.layers.split( offset, mask = fluid.layers.split(
input=offset_mask, input=offset_mask,
num_or_sections=[offset_channel, mask_channel], num_or_sections=[offset_channel, mask_channel],
...@@ -203,7 +210,13 @@ class ResNet(object): ...@@ -203,7 +210,13 @@ class ResNet(object):
ch_in = input.shape[1] ch_in = input.shape[1]
# the naming rule is same as pretrained weight # the naming rule is same as pretrained weight
name = self.na.fix_shortcut_name(name) name = self.na.fix_shortcut_name(name)
std_senet = getattr(self, 'std_senet', False)
if ch_in != ch_out or stride != 1 or (self.depth < 50 and is_first): if ch_in != ch_out or stride != 1 or (self.depth < 50 and is_first):
if std_senet:
if is_first:
return self._conv_norm(input, ch_out, 1, stride, name=name)
else:
return self._conv_norm(input, ch_out, 3, stride, name=name)
if max_pooling_in_short_cut and not is_first: if max_pooling_in_short_cut and not is_first:
input = fluid.layers.pool2d( input = fluid.layers.pool2d(
input=input, input=input,
...@@ -217,7 +230,13 @@ class ResNet(object): ...@@ -217,7 +230,13 @@ class ResNet(object):
else: else:
return input return input
def bottleneck(self, input, num_filters, stride, is_first, name, dcn_v2=False): def bottleneck(self,
input,
num_filters,
stride,
is_first,
name,
dcn_v2=False):
if self.variant == 'a': if self.variant == 'a':
stride1, stride2 = stride, 1 stride1, stride2 = stride, 1
else: else:
...@@ -236,9 +255,17 @@ class ResNet(object): ...@@ -236,9 +255,17 @@ class ResNet(object):
conv_name1, conv_name2, conv_name3, \ conv_name1, conv_name2, conv_name3, \
shortcut_name = self.na.fix_bottleneck_name(name) shortcut_name = self.na.fix_bottleneck_name(name)
conv_def = [[num_filters, 1, stride1, 'relu', 1, conv_name1], std_senet = getattr(self, 'std_senet', False)
[num_filters, 3, stride2, 'relu', groups, conv_name2], if std_senet:
[num_filters * expand, 1, 1, None, 1, conv_name3]] conv_def = [
[int(num_filters / 2), 1, stride1, 'relu', 1, conv_name1],
[num_filters, 3, stride2, 'relu', groups, conv_name2],
[num_filters * expand, 1, 1, None, 1, conv_name3]
]
else:
conv_def = [[num_filters, 1, stride1, 'relu', 1, conv_name1],
[num_filters, 3, stride2, 'relu', groups, conv_name2],
[num_filters * expand, 1, 1, None, 1, conv_name3]]
residual = input residual = input
for i, (c, k, s, act, g, _name) in enumerate(conv_def): for i, (c, k, s, act, g, _name) in enumerate(conv_def):
...@@ -250,7 +277,7 @@ class ResNet(object): ...@@ -250,7 +277,7 @@ class ResNet(object):
act=act, act=act,
groups=g, groups=g,
name=_name, name=_name,
dcn_v2=(i==1 and dcn_v2)) dcn_v2=(i == 1 and dcn_v2))
short = self._shortcut( short = self._shortcut(
input, input,
num_filters * expand, num_filters * expand,
...@@ -264,7 +291,13 @@ class ResNet(object): ...@@ -264,7 +291,13 @@ class ResNet(object):
return fluid.layers.elementwise_add( return fluid.layers.elementwise_add(
x=short, y=residual, act='relu', name=name + ".add.output.5") x=short, y=residual, act='relu', name=name + ".add.output.5")
def basicblock(self, input, num_filters, stride, is_first, name, dcn_v2=False): def basicblock(self,
input,
num_filters,
stride,
is_first,
name,
dcn_v2=False):
assert dcn_v2 is False, "Not implemented yet." assert dcn_v2 is False, "Not implemented yet."
conv0 = self._conv_norm( conv0 = self._conv_norm(
input=input, input=input,
...@@ -385,7 +418,6 @@ class ResNetC5(ResNet): ...@@ -385,7 +418,6 @@ class ResNetC5(ResNet):
norm_decay=0., norm_decay=0.,
variant='b', variant='b',
feature_maps=[5]): feature_maps=[5]):
super(ResNetC5, self).__init__( super(ResNetC5, self).__init__(depth, freeze_at, norm_type, freeze_norm,
depth, freeze_at, norm_type, freeze_norm, norm_decay, norm_decay, variant, feature_maps)
variant, feature_maps)
self.severed_head = True self.severed_head = True
...@@ -55,7 +55,8 @@ class SENet(ResNeXt): ...@@ -55,7 +55,8 @@ class SENet(ResNeXt):
norm_decay=0., norm_decay=0.,
variant='d', variant='d',
feature_maps=[2, 3, 4, 5], feature_maps=[2, 3, 4, 5],
dcn_v2_stages=[]): dcn_v2_stages=[],
std_senet=False):
super(SENet, self).__init__(depth, groups, group_width, freeze_at, super(SENet, self).__init__(depth, groups, group_width, freeze_at,
norm_type, freeze_norm, norm_decay, variant, norm_type, freeze_norm, norm_decay, variant,
feature_maps) feature_maps)
...@@ -64,6 +65,7 @@ class SENet(ResNeXt): ...@@ -64,6 +65,7 @@ class SENet(ResNeXt):
else: else:
self.stage_filters = [256, 512, 1024, 2048] self.stage_filters = [256, 512, 1024, 2048]
self.reduction_ratio = 16 self.reduction_ratio = 16
self.std_senet = std_senet
self._c1_out_chan_num = 128 self._c1_out_chan_num = 128
self._model_type = 'SEResNeXt' self._model_type = 'SEResNeXt'
self.dcn_v2_stages = dcn_v2_stages self.dcn_v2_stages = dcn_v2_stages
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册