예제 #1
0
def add_ResNet_roi_conv5_head(model, blob_in, dim_in, spatial_scale):
    """Adds an RoI feature transformation (e.g., RoI pooling) followed by a
    res5/conv5 head applied to each RoI."""
    # TODO(rbg): This contains Fast R-CNN specific config options making it non-
    # reusable; make this more generic with model-specific wrappers
    l = model.RoIFeatureTransform(
        blob_in,
        'pool5',
        blob_rois='rois',
        method=cfg.FAST_RCNN.ROI_XFORM_METHOD,
        resolution=cfg.FAST_RCNN.ROI_XFORM_RESOLUTION,
        sampling_ratio=cfg.FAST_RCNN.ROI_XFORM_SAMPLING_RATIO,
        spatial_scale=spatial_scale)

    l = model.net.RoIFeatureBoost([l, 'obn_scores'], l)

    # save memory
    if cfg.TRAIN.FREEZE_CONV_BODY:
        model.StopGradient(l, l)

    dim_bottleneck = cfg.RESNETS.NUM_GROUPS * cfg.RESNETS.WIDTH_PER_GROUP
    stride_init = int(cfg.FAST_RCNN.ROI_XFORM_RESOLUTION / 7)
    s, dim_in = add_stage(model, 'res5', 'pool5', 3, dim_in, 2048,
                          dim_bottleneck * 8, 1, stride_init)
    s = model.AveragePool(s, 'res5_pool', kernel=7)
    return s, 2048
예제 #2
0
def add_bpm_pse_outputs_c4(model, blob_in, dim):
    current = add_attr_outputs(model, blob_in, dim)

    # ReID stream
    num_attr = cfg.REID.PSE_VIEW
    attr_pred_list = ['attr_pred_' + str(i) for i in range(num_attr)]
    model.net.Split(
        current, attr_pred_list, split=[1 for i in range(num_attr)], axis=1)

    attr_feature_list = []
    for attr_id in range(num_attr):
        prefix = '_[v{}]'.format(attr_id)
        shape_0 = cfg.TRAIN.IMS_PER_BATCH if model.train else 1
        model.net.Reshape(
            attr_pred_list[attr_id],
            [attr_pred_list[attr_id], 'attr_old_shape_' + str(attr_id)],
            shape=[shape_0, 1, 1, 1])

        dim_bottleneck = cfg.RESNETS.NUM_GROUPS * cfg.RESNETS.WIDTH_PER_GROUP
        current, dim_out = add_stage(
            model,
            prefix + '_res5',
            blob_in,
            3,
            dim,
            2048,
            dim_bottleneck * 8,
            cfg.RESNETS.RES5_DILATION,
            stride_init=cfg.RESNETS.RES5_STRIDE)

        current = model.net.Mul(
            [current, attr_pred_list[attr_id]],
            prefix + '_scale',
            broadcast=True,
        )
        attr_feature_list.append(current)

    current = model.net.Sum(
        [attr_feature for attr_feature in attr_feature_list], 'v_scale')

    add_bpm_outputs(model, current, dim_out)