def _detection_block(self,
                         input,
                         channel,
                         conv_block_num=2,
                         is_first=False,
                         is_test=True,
                         name=None):
        assert channel % 2 == 0, \
            "channel {} cannot be divided by 2 in detection block {}" \
            .format(channel, name)

        conv = input
        for j in range(conv_block_num):
            conv = self._add_coord(conv, is_test=is_test)
            conv = self._conv_bn(conv,
                                 channel,
                                 filter_size=1,
                                 stride=1,
                                 padding=0,
                                 name='{}.{}.0'.format(name, j))
            if self.use_spp and is_first and j == 1:
                conv = self._spp_module(conv, name="spp")
                conv = self._conv_bn(conv,
                                     512,
                                     filter_size=1,
                                     stride=1,
                                     padding=0,
                                     name='{}.{}.spp.conv'.format(name, j))
            conv = self._conv_bn(conv,
                                 channel * 2,
                                 filter_size=3,
                                 stride=1,
                                 padding=1,
                                 name='{}.{}.1'.format(name, j))
            if self.drop_block and j == 0 and not is_first:
                conv = DropBlock(conv,
                                 block_size=self.block_size,
                                 keep_prob=self.keep_prob,
                                 is_test=is_test)

        if self.drop_block and is_first:
            conv = DropBlock(conv,
                             block_size=self.block_size,
                             keep_prob=self.keep_prob,
                             is_test=is_test)
        conv = self._add_coord(conv, is_test=is_test)
        route = self._conv_bn(conv,
                              channel,
                              filter_size=1,
                              stride=1,
                              padding=0,
                              name='{}.2'.format(name))
        new_route = self._add_coord(route, is_test=is_test)
        tip = self._conv_bn(new_route,
                            channel * 2,
                            filter_size=3,
                            stride=1,
                            padding=1,
                            name='{}.tip'.format(name))
        return route, tip
Beispiel #2
0
    def _detection_block(self, input, channel, is_test=True, name=None):
        assert channel % 2 == 0, \
            "channel {} cannot be divided by 2 in detection block {}" \
            .format(channel, name)

        conv = input
        for j in range(2):
            conv = self._conv_bn(
                conv,
                channel,
                filter_size=1,
                stride=1,
                padding=0,
                is_test=is_test,
                name='{}.{}.0'.format(name, j))
            conv = self._conv_bn(
                conv,
                channel * 2,
                filter_size=3,
                stride=1,
                padding=1,
                is_test=is_test,
                name='{}.{}.1'.format(name, j))
            if self.drop_block and j == 0 and channel != 512:
                conv = DropBlock(
                    conv,
                    block_size=self.block_size,
                    keep_prob=self.keep_prob,
                    is_test=is_test)

        if self.drop_block and channel == 512:
            conv = DropBlock(
                conv,
                block_size=self.block_size,
                keep_prob=self.keep_prob,
                is_test=is_test)
        route = self._conv_bn(
            conv,
            channel,
            filter_size=1,
            stride=1,
            padding=0,
            is_test=is_test,
            name='{}.2'.format(name))
        tip = self._conv_bn(
            route,
            channel * 2,
            filter_size=3,
            stride=1,
            padding=1,
            is_test=is_test,
            name='{}.tip'.format(name))
        return route, tip
Beispiel #3
0
 def _head(self,
           x,
           out_c,
           conv_num=1,
           head_out_c=None,
           name=None,
           is_test=False):
     head_out_c = self.head_conv if not head_out_c else head_out_c
     conv_w_std = 0.01 if '.hm' in name else 0.001
     conv_w_init = Normal(0, conv_w_std)
     for i in range(conv_num):
         conv_name = '{}.{}.conv'.format(name, i)
         if self.dcn_head:
             x = DeformConv(
                 x,
                 head_out_c,
                 3,
                 initializer=conv_w_init,
                 name=conv_name + '.dcn')
             x = fluid.layers.relu(x)
         else:
             x = fluid.layers.conv2d(
                 x,
                 head_out_c,
                 3,
                 padding=1,
                 param_attr=ParamAttr(
                     initializer=conv_w_init, name=conv_name + '.weight'),
                 bias_attr=ParamAttr(
                     learning_rate=2.,
                     regularizer=L2Decay(0.),
                     name=conv_name + '.bias'),
                 act='relu')
     if self.drop_block and '.hm' in name:
         x = DropBlock(
             x,
             block_size=self.block_size,
             keep_prob=self.keep_prob,
             is_test=is_test)
     bias_init = float(-np.log((1 - 0.01) / 0.01)) if '.hm' in name else 0.
     conv_b_init = Constant(bias_init)
     x = fluid.layers.conv2d(
         x,
         out_c,
         1,
         param_attr=ParamAttr(
             initializer=conv_w_init,
             name='{}.{}.weight'.format(name, conv_num)),
         bias_attr=ParamAttr(
             learning_rate=2.,
             regularizer=L2Decay(0.),
             name='{}.{}.bias'.format(name, conv_num),
             initializer=conv_b_init))
     return x
    def _conv_pred(self,
                   conv_feat,
                   num_filters,
                   is_test,
                   name,
                   name_feat=None):
        for i in range(self.stacked_convs):
            if i in self.dcn_v2_stages:
                conv_func = self.conv_type[1]
            else:
                conv_func = self.conv_type[0]
            conv_feat = conv_func(
                input=conv_feat,
                num_filters=self.seg_feat_channels,
                filter_size=3,
                stride=1,
                norm_type='gn',
                norm_groups=32,
                freeze_norm=False,
                act='relu',
                initializer=fluid.initializer.NormalInitializer(scale=0.01),
                norm_name='{}.{}.gn'.format(name, i),
                name='{}.{}'.format(name, i))
        if name_feat == 'bbox_head.solo_cate':
            bias_init = float(-np.log((1 - 0.01) / 0.01))
            bias_attr = ParamAttr(
                name="{}.bias".format(name_feat),
                initializer=fluid.initializer.Constant(value=bias_init))
        else:
            bias_attr = ParamAttr(name="{}.bias".format(name_feat))

        if self.drop_block:
            conv_feat = DropBlock(conv_feat,
                                  block_size=3,
                                  keep_prob=0.9,
                                  is_test=is_test)

        conv_feat = fluid.layers.conv2d(
            input=conv_feat,
            num_filters=num_filters,
            filter_size=3,
            stride=1,
            padding=1,
            param_attr=ParamAttr(
                name="{}.weight".format(name_feat),
                initializer=fluid.initializer.NormalInitializer(scale=0.01)),
            bias_attr=bias_attr,
            name=name + '_feat_')
        return conv_feat
Beispiel #5
0
    def _detection_block(self,
                         input,
                         channel,
                         conv_block_num=2,
                         is_first=False,
                         is_test=True,
                         name=None):
        conv_left = self._conv_bn(input,
                                  channel,
                                  act=self.act,
                                  filter_size=1,
                                  stride=1,
                                  padding=0,
                                  name='{}.left'.format(name))
        conv_right = self._conv_bn(input,
                                   channel,
                                   act=self.act,
                                   filter_size=1,
                                   stride=1,
                                   padding=0,
                                   name='{}.right'.format(name))
        for j in range(conv_block_num):
            conv_left = self._conv_bn(conv_left,
                                      channel,
                                      act=self.act,
                                      filter_size=1,
                                      stride=1,
                                      padding=0,
                                      name='{}.left.{}'.format(name, 2 * j))
            if self.use_spp and is_first and j == 1:
                c = conv_left.shape[1]
                conv_left = self._spp_module(conv_left, name="spp")
                conv_left = self._conv_bn(conv_left,
                                          c,
                                          act=self.act,
                                          filter_size=1,
                                          stride=1,
                                          padding=0,
                                          name='{}.left.{}'.format(
                                              name, 2 * j + 1))
            else:
                conv_left = self._conv_bn(conv_left,
                                          channel,
                                          act=self.act,
                                          filter_size=3,
                                          stride=1,
                                          padding=1,
                                          name='{}.left.{}'.format(
                                              name, 2 * j + 1))
            if self.drop_block and j == 1:
                conv_left = DropBlock(conv_left,
                                      block_size=self.block_size,
                                      keep_prob=self.keep_prob,
                                      is_test=is_test)

        conv = fluid.layers.concat(input=[conv_left, conv_right], axis=1)
        conv = self._conv_bn(conv,
                             channel * 2,
                             act=self.act,
                             filter_size=1,
                             stride=1,
                             padding=0,
                             name=name)
        return conv, conv
Beispiel #6
0
    def _detection_block(self,
                         input,
                         channel,
                         is_first=False,
                         is_test=True,
                         name=None):
        assert channel % 2 == 0, \
            "channel {} cannot be divided by 2 in detection block {}" \
            .format(channel, name)

        conv = input
        if self.use_spp and is_first:
            c = conv.shape[1]
            conv = self._spp_module(conv, name="spp")
            conv = self._conv_bn(conv,
                                 c,
                                 filter_size=1,
                                 stride=1,
                                 padding=0,
                                 name='{}.spp.conv'.format(name))

        if self.drop_block:
            conv = DropBlock(conv,
                             block_size=self.block_size,
                             keep_prob=self.keep_prob,
                             is_test=is_test)

        conv = self._conv_bn(conv,
                             ch_out=channel,
                             filter_size=1,
                             stride=1,
                             padding=0,
                             groups=1,
                             name='{}.0'.format(name))
        conv = self._conv_bn(conv,
                             channel,
                             filter_size=5,
                             stride=1,
                             padding=2,
                             groups=channel,
                             name='{}.1'.format(name))
        conv = self._conv_bn(conv,
                             channel,
                             filter_size=1,
                             stride=1,
                             padding=0,
                             name='{}.2'.format(name))
        route = self._conv_bn(conv,
                              channel,
                              filter_size=5,
                              stride=1,
                              padding=2,
                              groups=channel,
                              name='{}.route'.format(name))
        tip = self._conv_bn(route,
                            channel,
                            filter_size=1,
                            stride=1,
                            padding=0,
                            name='{}.tip'.format(name))
        return route, tip