Example #1
0
 def across_down(self, stage_num, level_num, dim_reduced, init, norm):
     feature = self.feature_grids[stage_num][level_num]
     feature = mx.sym.UpSampling(
         feature,
         scale=2,
         sample_type='nearest',
         name='P%s_%s_acrossdown_upsample' % (level_num, stage_num),
         num_args=1,
     )
     feature = X.reluconvbn(data=feature,filters=dim_reduced, kernel=3, pad=1, stride=1, init=init, norm=norm,\
                             name='P%s_acrossdown_conv'%level_num, prefix='S%s_'%stage_num)
     p0_feature = self.feature_grids[0][level_num - 1]
     feature = mx.sym.slice_like(feature,
                                 p0_feature,
                                 name='P%s_%s_slicelike' %
                                 (stage_num, level_num))
     return feature
Example #2
0
    def get_fused_P_feature(p_features, stage, dim_reduced, init, norm):
        prefix = "S{}_".format(stage)
        with mx.name.Prefix(prefix):
            P3_0 = p_features['S{}_P3'.format(stage - 1)]  # s8
            P4_0 = p_features['S{}_P4'.format(stage - 1)]  # s16
            P5_0 = p_features['S{}_P5'.format(stage - 1)]  # s32
            P6_0 = p_features['S{}_P6'.format(stage - 1)]  # s64
            P7_0 = p_features['S{}_P7'.format(stage - 1)]  # s128
            # P4_1 = gp(P6_0, P4_0)
            P6_0_to_P4 = mx.sym.UpSampling(P6_0,
                                           scale=4,
                                           sample_type='nearest',
                                           name="P6_0_to_P4",
                                           num_args=1)
            P6_0_to_P4 = mx.sym.slice_like(P6_0_to_P4, P4_0)
            P4_1 = merge_gp(P6_0_to_P4, P4_0, name="gp_P6_0_P4_0")
            P4_1 = X.reluconvbn(P4_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_1",
                                prefix=prefix)
            # P4_2 = sum(P4_0, P4_1)
            P4_2 = X.merge_sum([P4_0, P4_1], name="sum_P4_0_P4_1")
            P4_2 = X.reluconvbn(P4_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_2",
                                prefix=prefix)
            # P3_3 = sum(P4_2, P3_0) end node
            P4_2_to_P3 = mx.sym.UpSampling(P4_2,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P4_2_to_P3",
                                           num_args=1)
            P4_2_to_P3 = mx.sym.slice_like(P4_2_to_P3, P3_0)
            P3_3 = X.merge_sum([P4_2_to_P3, P3_0], name="sum_P4_2_P3_0")
            P3_3 = X.reluconvbn(P3_3,
                                dim_reduced,
                                init,
                                norm,
                                name="P3_3",
                                prefix=prefix)
            P3 = P3_3
            # P4_4 = sum(P4_2, P3_3) end node
            P3_3_to_P4 = X.pool(P3_3,
                                name="P3_3_to_P4",
                                kernel=2,
                                stride=2,
                                pad=0)
            P3_3_to_P4 = mx.sym.slice_like(P3_3_to_P4, P4_2)
            P4_4 = X.merge_sum([P4_2, P3_3_to_P4], name="sum_P4_4_P3_3")
            P4_4 = X.reluconvbn(P4_4,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_4",
                                prefix=prefix)
            P4 = P4_4
            # P5_5 = sum(gp(P4_4, P3_3), P5_0) end node
            P4_4_to_P5 = X.pool(P4_4,
                                kernel=2,
                                stride=2,
                                name="P4_4_to_P5",
                                pad=0)
            P4_4_to_P5 = mx.sym.slice_like(P4_4_to_P5, P5_0)
            P3_3_to_P5 = X.pool(P3_3,
                                kernel=4,
                                stride=4,
                                name="P3_3_to_P5",
                                pad=0)
            P3_3_to_P5 = mx.sym.slice_like(P3_3_to_P5, P5_0)
            gp_P4_4_P3_3 = merge_gp(P4_4_to_P5,
                                    P3_3_to_P5,
                                    name="gp_P4_4_P3_3")
            P5_5 = X.merge_sum([gp_P4_4_P3_3, P5_0],
                               name="sum_[gp_P4_4_P3_3]_P5_0")
            P5_5 = X.reluconvbn(P5_5,
                                dim_reduced,
                                init,
                                norm,
                                name="P5_5",
                                prefix=prefix)
            P5 = P5_5
            # P7_6 = sum(gp(P5_5, P4_2), P7_0) end node
            P4_2_to_P7 = X.pool(P4_2,
                                name="P4_2_to_P7",
                                kernel=8,
                                stride=8,
                                pad=0)
            P4_2_to_P7 = mx.sym.slice_like(P4_2_to_P7, P7_0)
            P5_5_to_P7 = X.pool(P5_5,
                                name="P5_5_to_P7",
                                kernel=4,
                                stride=4,
                                pad=0)
            P5_5_to_P7 = mx.sym.slice_like(P5_5_to_P7, P7_0)
            gp_P5_5_P4_2 = merge_gp(P5_5_to_P7,
                                    P4_2_to_P7,
                                    name="gp_P5_5_P4_2")
            P7_6 = X.merge_sum([gp_P5_5_P4_2, P7_0],
                               name="sum_[gp_P5_5_P4_2]_P7_0")
            P7_6 = X.reluconvbn(P7_6,
                                dim_reduced,
                                init,
                                norm,
                                name="P7_6",
                                prefix=prefix)
            P7 = P7_6
            # P6_7 = gp(P7_6, P5_5) end node
            P7_6_to_P6 = mx.sym.UpSampling(P7_6,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P7_6_to_P6",
                                           num_args=1)
            P7_6_to_P6 = mx.sym.slice_like(P7_6_to_P6, P6_0)
            P5_5_to_P6 = X.pool(P5_5,
                                name="p5_5_to_P6",
                                kernel=2,
                                stride=2,
                                pad=0)
            P5_5_to_P6 = mx.sym.slice_like(P5_5_to_P6, P6_0)
            P6_7 = merge_gp(P7_6_to_P6,
                            P5_5_to_P6,
                            name="gp_P7_6_to_P6_P5_5_to_P6")
            P6_7 = X.reluconvbn(P6_7,
                                dim_reduced,
                                init,
                                norm,
                                name="P6_7",
                                prefix=prefix)
            P6 = P6_7

            return {
                'S{}_P3'.format(stage): P3,
                'S{}_P4'.format(stage): P4,
                'S{}_P5'.format(stage): P5,
                'S{}_P6'.format(stage): P6,
                'S{}_P7'.format(stage): P7
            }
Example #3
0
    def get_fused_P_feature(p_features, stage, dim_reduced, init, norm):
        prefix = "S{}_".format(stage)
        with mx.name.Prefix(prefix):
            P3_0 = p_features['S{}_P3'.format(stage - 1)]  # s8
            P4_0 = p_features['S{}_P4'.format(stage - 1)]  # s16
            P5_0 = p_features['S{}_P5'.format(stage - 1)]  # s32
            P6_0 = p_features['S{}_P6'.format(stage - 1)]  # s64
            P7_0 = p_features['S{}_P7'.format(stage - 1)]  # s128

            # P7_1
            P7_1 = P7_0
            # P6_1 = sum(P6_0, P7_1)
            P7_1_to_P6 = mx.sym.UpSampling(P7_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P7_1_to_P6",
                                           num_args=1)
            P6_1 = X.merge_sum([P6_0, P7_1_to_P6], name="sum_P6_0_P7_1")
            P6_1 = X.reluconvbn(P6_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P6_1",
                                prefix=prefix)
            # P5_1 = sum(P5_0, P6_1)
            P6_1_to_P5 = mx.sym.UpSampling(P6_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P6_1_to_P5",
                                           num_args=1)
            P5_1 = X.merge_sum([P5_0, P6_1_to_P5], name="sum_P5_0_P6_1")
            P5_1 = X.reluconvbn(P5_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P5_1",
                                prefix=prefix)
            # P4_1 = sum(P4_0, P5_1)
            P5_1_to_P4 = mx.sym.UpSampling(P5_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P5_1_to_P4",
                                           num_args=1)
            P4_1 = X.merge_sum([P4_0, P5_1_to_P4], name="sum_P4_0_P5_1")
            P4_1 = X.reluconvbn(P4_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_1",
                                prefix=prefix)
            # P3_1 = sum(P3_0, P4_1)
            P4_1_to_P3 = mx.sym.UpSampling(P4_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P4_1_to_P3",
                                           num_args=1)
            P3_1 = X.merge_sum([P3_0, P4_1_to_P3], name="sum_P3_0_P4_1")
            P3_1 = X.reluconvbn(P3_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P3_1",
                                prefix=prefix)

            P3_2 = P3_1
            P3 = P3_2

            # P4_2 = sum(P3_2, P4_1)
            P3_2_to_P4 = X.pool(P3_2,
                                name="P3_2_to_P4",
                                kernel=2,
                                stride=2,
                                pad=0)
            P4_2 = X.merge_sum([P4_1, P3_2_to_P4], name="sum_P4_1_P3_2")
            P4_2 = X.reluconvbn(P4_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_2",
                                prefix=prefix)
            P4 = P4_2
            # P5_2 = sum(P4_2, P5_1)
            P4_2_to_P5 = X.pool(P4_2,
                                name="P4_2_to_P5",
                                kernel=2,
                                stride=2,
                                pad=0)
            P5_2 = X.merge_sum([P5_1, P4_2_to_P5], name="sum_P5_1_P4_2")
            P5_2 = X.reluconvbn(P5_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P5_2",
                                prefix=prefix)
            P5 = P5_2
            # P6_2 = sum(P5_2, P6_1)
            P5_2_to_P6 = X.pool(P5_2,
                                name="P5_2_to_P6",
                                kernel=2,
                                stride=2,
                                pad=0)
            P6_2 = X.merge_sum([P6_1, P5_2_to_P6], name="sum_P6_1_P5_2")
            P6_2 = X.reluconvbn(P6_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P6_2",
                                prefix=prefix)
            P6 = P6_2
            # P7_2 = sum(P6_2, P7_1)
            P6_2_to_P7 = X.pool(P6_2,
                                name="P6_2_to_P7",
                                kernel=2,
                                stride=2,
                                pad=0)
            P7_2 = X.merge_sum([P7_1, P6_2_to_P7], name="sum_P7_1_P6_2")
            P7_2 = X.reluconvbn(P7_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P7_2",
                                prefix=prefix)
            P7 = P7_2

            return {
                'S{}_P3'.format(stage): P3,
                'S{}_P4'.format(stage): P4,
                'S{}_P5'.format(stage): P5,
                'S{}_P6'.format(stage): P6,
                'S{}_P7'.format(stage): P7
            }
Example #4
0
    def get_fused_P_feature(p_features, stage, dim_reduced, init, norm):
        prefix = "S{}_".format(stage)
        with mx.name.Prefix(prefix):
            P2_0 = p_features['S{}_P2'.format(stage - 1)]  # s4
            P3_0 = p_features['S{}_P3'.format(stage - 1)]  # s8
            P4_0 = p_features['S{}_P4'.format(stage - 1)]  # s16
            P5_0 = p_features['S{}_P5'.format(stage - 1)]  # s32
            P6_0 = p_features['S{}_P6'.format(stage - 1)]  # s64

            P6_1 = P6_0
            P6_1_to_P5 = mx.sym.UpSampling(P6_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P6_1_to_P5",
                                           num_args=1)
            P6_1_to_P5 = mx.sym.slice_like(P6_1_to_P5, P5_0)
            P5_1 = X.merge_sum([P5_0, P6_1_to_P5], name="sum_P5_0_P6_1")
            P5_1 = X.reluconvbn(P5_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P5_1",
                                prefix=prefix)

            # P4_1 = sum(P4_0, P5_1)
            P5_1_to_P4 = mx.sym.UpSampling(P5_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P5_1_to_P4",
                                           num_args=1)
            P5_1_to_P4 = mx.sym.slice_like(P5_1_to_P4, P4_0)
            P4_1 = X.merge_sum([P4_0, P5_1_to_P4], name="sum_P4_0_P5_1")
            P4_1 = X.reluconvbn(P4_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_1",
                                prefix=prefix)

            P4_1_to_P3 = mx.sym.UpSampling(P4_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P4_1_to_P3",
                                           num_args=1)
            P4_1_to_P3 = mx.sym.slice_like(P4_1_to_P3, P3_0)
            P3_1 = X.merge_sum([P3_0, P4_1_to_P3], name="sum_P3_0_P4_1")
            P3_1 = X.reluconvbn(P3_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P3_1",
                                prefix=prefix)

            P3_1_to_P2 = mx.sym.UpSampling(P3_1,
                                           scale=2,
                                           sample_type='nearest',
                                           name="P3_1_to_P2",
                                           num_args=1)
            P3_1_to_P2 = mx.sym.slice_like(P3_1_to_P2, P2_0)
            P2_1 = X.merge_sum([P2_0, P3_1_to_P2], name="sum_P2_0_P3_1")
            P2_1 = X.reluconvbn(P2_1,
                                dim_reduced,
                                init,
                                norm,
                                name="P2_1",
                                prefix=prefix)

            P2_2 = P2_1
            P2 = P2_2

            P2_2_to_P3 = X.pool(P2_2,
                                name="P2_2_to_P3",
                                kernel=3,
                                stride=2,
                                pad=1)
            P3_2 = X.merge_sum([P3_1, P2_2_to_P3], name="sum_P3_1_P2_2")
            P3_2 = X.reluconvbn(P3_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P3_2",
                                prefix=prefix)
            P3 = P3_2

            P3_2_to_P4 = X.pool(P3_2,
                                name="P3_2_to_P4",
                                kernel=3,
                                stride=2,
                                pad=1)
            P4_2 = X.merge_sum([P4_1, P3_2_to_P4], name="sum_P4_1_P3_2")
            P4_2 = X.reluconvbn(P4_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P4_2",
                                prefix=prefix)
            P4 = P4_2

            P4_2_to_P5 = X.pool(P4_2,
                                name="P4_2_to_P5",
                                kernel=3,
                                stride=2,
                                pad=1)
            P5_2 = X.merge_sum([P5_1, P4_2_to_P5], name="sum_P5_1_P4_2")
            P5_2 = X.reluconvbn(P5_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P5_2",
                                prefix=prefix)
            P5 = P5_2

            P5_2_to_P6 = X.pool(P5_2,
                                name="P5_2_to_P6",
                                kernel=3,
                                stride=2,
                                pad=1)
            P6_2 = X.merge_sum([P6_1, P5_2_to_P6], name="sum_P6_1_P5_2")
            P6_2 = X.reluconvbn(P6_2,
                                dim_reduced,
                                init,
                                norm,
                                name="P6_2",
                                prefix=prefix)
            P6 = P6_2

            return {
                'S{}_P2'.format(stage): P2,
                'S{}_P3'.format(stage): P3,
                'S{}_P4'.format(stage): P4,
                'S{}_P5'.format(stage): P5,
                'S{}_P6'.format(stage): P6,
            }
Example #5
0
 def across_skip(self, stage_num, level_num, curr_stage_num, dim_reduced,
                 init, norm):
     feature = self.feature_grids[stage_num][level_num]
     feature = X.reluconvbn(data=feature,filters=dim_reduced, kernel=1, pad=0, stride=1, init=init, norm=norm,\
                             name='P%s_acrossskip_conv'%level_num, prefix='S%s_2_%s'%(stage_num, curr_stage_num))
     return feature
Example #6
0
 def same_up(self, stage_num, level_num, dim_reduced, init, norm):
     feature = self.feature_grids[stage_num][level_num]
     feature = X.reluconvbn(data=feature,filters=dim_reduced, kernel=3, pad=1, stride=2, init=init, norm=norm,\
                             name='P%s_sameup_conv'%level_num, prefix='S%s_'%stage_num)
     return feature