예제 #1
0
def create_fast_rcnn_predictor(conv_out, rois, fc_layers, cfg):
    # RCNN
    roi_out = roipooling(conv_out,
                         rois,
                         cntk.MAX_POOLING,
                         (cfg["MODEL"].ROI_DIM, cfg["MODEL"].ROI_DIM),
                         spatial_scale=1 / 16.0)
    fc_out = fc_layers(roi_out)

    # prediction head
    W_pred = parameter(shape=(4096, cfg["DATA"].NUM_CLASSES),
                       init=normal(scale=0.01),
                       name="cls_score.W")
    b_pred = parameter(shape=cfg["DATA"].NUM_CLASSES,
                       init=0,
                       name="cls_score.b")
    cls_score = plus(times(fc_out, W_pred), b_pred, name='cls_score')

    # regression head
    W_regr = parameter(shape=(4096, cfg["DATA"].NUM_CLASSES * 4),
                       init=normal(scale=0.001),
                       name="bbox_regr.W")
    b_regr = parameter(shape=cfg["DATA"].NUM_CLASSES * 4,
                       init=0,
                       name="bbox_regr.b")
    bbox_pred = plus(times(fc_out, W_regr), b_regr, name='bbox_regr')

    return cls_score, bbox_pred
def create_fast_rcnn_predictor(conv_out, rois, fc_layers):
    # RCNN
    roi_out = roipooling(conv_out,
                         rois,
                         cntk.MAX_POOLING, (roi_dim, roi_dim),
                         spatial_scale=1 / 16.0)
    print("roi_out shape:{}".format(roi_out.shape))
    fc_out = fc_layers(roi_out)

    # prediction head
    fea_map_dim = globalvars['fea_map_dim']
    W_pred = parameter(shape=(fea_map_dim, globalvars['num_classes']),
                       init=normal(scale=0.01),
                       name="cls_score.W")
    b_pred = parameter(shape=globalvars['num_classes'],
                       init=0,
                       name="cls_score.b")
    cls_score = plus(times(fc_out, W_pred), b_pred, name='cls_score')

    # regression head
    W_regr = parameter(shape=(fea_map_dim, globalvars['num_classes'] * 4),
                       init=normal(scale=0.001),
                       name="bbox_regr.W")
    b_regr = parameter(shape=globalvars['num_classes'] * 4,
                       init=0,
                       name="bbox_regr.b")
    bbox_pred = plus(times(fc_out, W_regr), b_regr, name='bbox_regr')

    return cls_score, bbox_pred
예제 #3
0
def test_MaxRoiPool(tmpdir):
    input_map = [[
        [1., 2., 3.],  # (1, 3, 3) input operand (conv feature map)
        [4., 5., 6.],
        [7., 8., 9.]
    ]]
    input_rois = [[1, 1, 2, 2]]

    conv_input = np.asarray(input_map, dtype=np.float32)
    roi_input = np.asarray(input_rois, dtype=np.float32)

    a = C.input_variable(shape=conv_input.shape,
                         dtype=np.float32,
                         needs_gradient=True,
                         name='a')

    b = C.input_variable(shape=roi_input.shape,
                         dtype=np.float32,
                         needs_gradient=False,
                         name='b')

    # adding batch and sequence axis
    conv_input.shape = (1, ) + conv_input.shape
    roi_input.shape = (1, ) + roi_input.shape

    model = C.roipooling(a, b, C.MAX_POOLING, (3, 3), 1.)

    verify_two_input(model, conv_input, roi_input, tmpdir, 'MaxRoiPool_1')
예제 #4
0
def test_MaxRoiPool(tmpdir, dtype):
    pytest.skip(
        'MaxRoiPool is failing with ONNX shape inference (input rois). RuntimeError: [ShapeInferenceError] RoIs tensor must have 2 dimensions'
    )
    with C.default_options(dtype=dtype):
        input_map = [[
            [1., 2., 3.],  # (1, 3, 3) input operand (conv feature map)
            [4., 5., 6.],
            [7., 8., 9.]
        ]]
        input_rois = [[1, 1, 2, 2]]

        conv_input = np.asarray(input_map, dtype=dtype)
        roi_input = np.asarray(input_rois, dtype=dtype)

        a = C.input_variable(shape=conv_input.shape,
                             dtype=dtype,
                             needs_gradient=True,
                             name='a')

        b = C.input_variable(shape=roi_input.shape,
                             dtype=dtype,
                             needs_gradient=False,
                             name='b')

        # adding batch and sequence axis
        conv_input.shape = (1, ) + conv_input.shape
        roi_input.shape = (1, ) + roi_input.shape

        model = C.roipooling(a, b, C.MAX_POOLING, (3, 3), 1.)

        verify_two_input(model, conv_input, roi_input, tmpdir, 'MaxRoiPool_1')
예제 #5
0
def test_MaxRoiPool(tmpdir, dtype):
    pytest.skip('MaxRoiPool is failing with ONNX shape inference (input rois). RuntimeError: [ShapeInferenceError] RoIs tensor must have 2 dimensions')
    with C.default_options(dtype = dtype):
        input_map = [[[1., 2., 3.],       # (1, 3, 3) input operand (conv feature map)
               [4., 5., 6.],
               [7., 8., 9.]]]
        input_rois = [[1, 1, 2, 2]]

        conv_input = np.asarray(input_map, dtype=dtype)
        roi_input = np.asarray(input_rois, dtype=dtype)

        a = C.input_variable(shape=conv_input.shape,
                    dtype=dtype,
                    needs_gradient=True,
                    name='a')

        b = C.input_variable(shape=roi_input.shape,
                    dtype=dtype,
                    needs_gradient=False,
                    name='b')

        # adding batch and sequence axis
        conv_input.shape     = (1,) + conv_input.shape
        roi_input.shape      = (1,) + roi_input.shape

        model = C.roipooling(a, b, C.MAX_POOLING, (3,3), 1.)

        verify_two_input(model, conv_input, roi_input, tmpdir, 'MaxRoiPool_1')
예제 #6
0
def test_MaxRoiPool(tmpdir):
    input_map = [[[1., 2., 3.],       # (1, 3, 3) input operand (conv feature map)
           [4., 5., 6.],
           [7., 8., 9.]]]
    input_rois = [[1, 1, 2, 2]]

    conv_input = np.asarray(input_map, dtype=np.float32)
    roi_input = np.asarray(input_rois, dtype=np.float32)

    a = C.input_variable(shape=conv_input.shape,
                dtype=np.float32,
                needs_gradient=True,
                name='a')

    b = C.input_variable(shape=roi_input.shape,
                dtype=np.float32,
                needs_gradient=False,
                name='b')

    # adding batch and sequence axis
    conv_input.shape     = (1,) + conv_input.shape
    roi_input.shape      = (1,) + roi_input.shape

    model = C.roipooling(a, b, C.MAX_POOLING, (3,3), 1.)

    verify_two_input(model, conv_input, roi_input, tmpdir, 'MaxRoiPool_1')
예제 #7
0
def create_fast_rcnn_predictor(conv_out, rois, fc_layers, cfg):
    # RCNN
    roi_out = roipooling(conv_out, rois, cntk.MAX_POOLING, (cfg["MODEL"].ROI_DIM, cfg["MODEL"].ROI_DIM), spatial_scale=1/16.0)
    fc_out = fc_layers(roi_out)

    # prediction head
    W_pred = parameter(shape=(4096, cfg["DATA"].NUM_CLASSES), init=normal(scale=0.01), name="cls_score.W")
    b_pred = parameter(shape=cfg["DATA"].NUM_CLASSES, init=0, name="cls_score.b")
    cls_score = plus(times(fc_out, W_pred), b_pred, name='cls_score')

    # regression head
    W_regr = parameter(shape=(4096, cfg["DATA"].NUM_CLASSES*4), init=normal(scale=0.001), name="bbox_regr.W")
    b_regr = parameter(shape=cfg["DATA"].NUM_CLASSES*4, init=0, name="bbox_regr.b")
    bbox_pred = plus(times(fc_out, W_regr), b_regr, name='bbox_regr')

    return cls_score, bbox_pred
예제 #8
0
def create_fast_rcnn_predictor(conv_out, rois, fc_layers):
    # RCNN
    roi_out = roipooling(conv_out, rois, cntk.MAX_POOLING, (roi_dim, roi_dim), spatial_scale=1/16.0)
    fc_out = fc_layers(roi_out)

    # prediction head
    W_pred = parameter(shape=(4096, globalvars['num_classes']), init=normal(scale=0.01), name="cls_score.W")
    b_pred = parameter(shape=globalvars['num_classes'], init=0, name="cls_score.b")
    cls_score = plus(times(fc_out, W_pred), b_pred, name='cls_score')

    # regression head
    W_regr = parameter(shape=(4096, globalvars['num_classes']*4), init=normal(scale=0.001), name="bbox_regr.W")
    b_regr = parameter(shape=globalvars['num_classes']*4, init=0, name="bbox_regr.b")
    bbox_pred = plus(times(fc_out, W_regr), b_regr, name='bbox_regr')

    return cls_score, bbox_pred
예제 #9
0
def test_op_roipooling(input_map, input_rois, expected_fwd, expected_bkwd,
                       device_id, precision):
    dt = PRECISION_TO_TYPE[precision]

    # AA == as numpy array
    conv_input = AA(input_map, dtype=dt)
    roi_input = AA(input_rois, dtype=dt)
    exp_fwd_value = AA(expected_fwd, dtype=dt)
    exp_bkwd_value = AA(expected_bkwd, dtype=dt)

    # adding batch, sequence and roi axis
    exp_fwd_value.shape = (1, 1, 1) + exp_fwd_value.shape
    exp_bkwd_value.shape = (1, 1) + exp_bkwd_value.shape

    # I == define cntk input variables
    a = I(shape=conv_input.shape,
          dtype=sanitize_dtype_cntk(precision),
          needs_gradient=True,
          name='a')

    b = I(shape=roi_input.shape,
          dtype=sanitize_dtype_cntk(precision),
          needs_gradient=False,
          name='b')

    # adding batch and sequence axis
    conv_input.shape = (1, 1) + conv_input.shape
    roi_input.shape = (1, 1) + roi_input.shape

    from cntk import roipooling
    input_op = roipooling(a, b, (3, 3))

    forward_input = {a: conv_input, b: roi_input}
    expected_backward = {a: exp_bkwd_value}

    unittest_helper(input_op,
                    forward_input,
                    exp_fwd_value,
                    expected_backward,
                    device_id=device_id,
                    precision=precision)
예제 #10
0
def test_op_maxroipooling(input_map, input_rois, expected_fwd, expected_bkwd, device_id, precision):
    dt = PRECISION_TO_TYPE[precision]

    # AA == as numpy array
    conv_input        = AA(input_map, dtype=dt)
    roi_input         = AA(input_rois, dtype=dt)
    exp_fwd_value     = AA(expected_fwd, dtype=dt)
    exp_bkwd_value    = AA(expected_bkwd, dtype=dt)

    # adding batch, sequence and roi axis
    exp_fwd_value.shape  = (1,1) + exp_fwd_value.shape
    exp_bkwd_value.shape = (1,) + exp_bkwd_value.shape

    # I == define cntk input variables
    a = C.input_variable(shape=conv_input.shape,
                dtype=sanitize_dtype_cntk(precision),
                needs_gradient=True,
                name='a')

    b = C.input_variable(shape=roi_input.shape,
                dtype=sanitize_dtype_cntk(precision),
                needs_gradient=False,
                name='b')

    # adding batch and sequence axis
    conv_input.shape     = (1,) + conv_input.shape
    roi_input.shape      = (1,) + roi_input.shape

    from cntk import roipooling
    input_op = roipooling(a, b, C.MAX_POOLING, (3,3), 1.)

    forward_input = {a: conv_input, b: roi_input}
    expected_backward = {a: exp_bkwd_value}

    unittest_helper(input_op,
                    forward_input, exp_fwd_value, expected_backward,
                    device_id=device_id, precision=precision)