Пример #1
0
def test_net(imageset, year, root_path, devkit_path, prefix, epoch, ctx):
    """
    wrapper for detector
    :param imageset: image set to test on
    :param year: year of image set
    :param root_path: 'data' folder path
    :param devkit_path: 'VOCdevkit' folder path
    :param prefix: new model prefix
    :param epoch: new model epoch
    :param ctx: context to evaluate in
    :return: None
    """
    # set up logger
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # load testing data
    voc, roidb = load_test_roidb(imageset, year, root_path, devkit_path)
    test_data = ROIIter(roidb, ctx=ctx, batch_size=1, shuffle=False, mode='test')

    # load model
    args, auxs = load_param(prefix, epoch, convert=True, ctx=ctx)

    # load symbol
    sym = get_symbol_vgg_test()

    # detect
    detector = Detector(sym, ctx, args, auxs)
    pred_eval(detector, test_data, voc, vis=False)
Пример #2
0
def test_net(imageset, year, root_path, devkit_path, prefix, epoch, ctx):
    """
    wrapper for detector
    :param imageset: image set to test on
    :param year: year of image set
    :param root_path: 'data' folder path
    :param devkit_path: 'VOCdevkit' folder path
    :param prefix: new model prefix
    :param epoch: new model epoch
    :param ctx: context to evaluate in
    :return: None
    """
    # set up logger
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # load testing data
    voc, roidb = load_test_roidb(imageset, year, root_path, devkit_path)
    test_data = ROIIter(roidb,
                        ctx=ctx,
                        batch_size=1,
                        shuffle=False,
                        mode='test')

    # load model
    args, auxs = load_param(prefix, epoch, convert=True, ctx=ctx)

    # load symbol
    sym = get_symbol_vgg_test()

    # detect
    detector = Detector(sym, ctx, args, auxs)
    pred_eval(detector, test_data, voc, vis=False)
Пример #3
0
def get_net(prefix, epoch, ctx):
    args, auxs = load_param(prefix, epoch, convert=True, ctx=ctx)
    sym = get_symbol_vgg_test()
    detector = Detector(sym, ctx, args, auxs)
    return detector
Пример #4
0
            bias = bias.reshape(arg_shape_dic[bias_name])
            arg_params[bias_name] = mx.nd.zeros(bias.shape)
            arg_params[bias_name][:] = bias

            if first_conv and (layer_type == 'Convolution' or layer_type == 4):
                first_conv = False

    return arg_params


proto_path = os.path.join(fast_rcnn_path, 'models', 'VGG16', 'test.prototxt')
model_path = os.path.join(fast_rcnn_path, 'data', 'fast_rcnn_models',
                          'vgg16_fast_rcnn_iter_40000.caffemodel')

symbol = get_symbol_vgg_test()
arg_shapes, out_shapes, aux_shapes = symbol.infer_shape(**{
    'data': (1, 3, 224, 224),
    'rois': (1, 5)
})
arg_shape_dic = {
    name: shape
    for name, shape in zip(symbol.list_arguments(), arg_shapes)
}

arg_params = load_model(proto_path, model_path, arg_shape_dic)

model = mx.model.FeedForward(ctx=mx.cpu(),
                             symbol=symbol,
                             arg_params=arg_params,
                             aux_params={},
Пример #5
0
            
            if weight_name not in arg_shape_dic:
                print(weight_name + ' not found in arg_shape_dic.')
                continue
            wmat = wmat.reshape(arg_shape_dic[weight_name])
            arg_params[weight_name] = mx.nd.zeros(wmat.shape)
            arg_params[weight_name][:] = wmat

            bias = bias.reshape(arg_shape_dic[bias_name])
            arg_params[bias_name] = mx.nd.zeros(bias.shape)
            arg_params[bias_name][:] = bias

            if first_conv and (layer_type == 'Convolution' or layer_type == 4):
                first_conv = False
    
    return arg_params

proto_path = os.path.join(fast_rcnn_path, 'models', 'VGG16', 'test.prototxt')
model_path = os.path.join(fast_rcnn_path, 'data', 'fast_rcnn_models', 'vgg16_fast_rcnn_iter_40000.caffemodel')

symbol = get_symbol_vgg_test()
arg_shapes, out_shapes, aux_shapes = symbol.infer_shape(**{'data': (1, 3, 224, 224), 'rois': (1, 5)})
arg_shape_dic = { name: shape for name, shape in zip(symbol.list_arguments(), arg_shapes) }

arg_params = load_model(proto_path, model_path, arg_shape_dic)

model = mx.model.FeedForward(ctx=mx.cpu(), symbol=symbol, arg_params=arg_params,
                             aux_params={}, num_epoch=1,
                             learning_rate=0.01, momentum=0.9, wd=0.0001)
model.save('model/ref')
Пример #6
0
def get_net(prefix, epoch, ctx):
    args, auxs = load_param(prefix, epoch, convert=True, ctx=ctx)
    sym = get_symbol_vgg_test()
    detector = Detector(sym, ctx, args, auxs)
    return detector