Exemplo n.º 1
0
def test_model_inference():
    # get all models
    from resnest.gluon.model_store import _model_sha1
    from resnest.gluon import get_model

    model_list = _model_sha1.keys()

    x = mx.random.uniform(shape=(1, 3, 224, 224))
    for model_name in model_list:
        print('Doing: ', model_name)
        model = get_model(model_name, pretrained=True)
        y = model(x)
Exemplo n.º 2
0
    num_gpus = opt.num_gpus
    if num_gpus > 0:
        batch_size *= num_gpus
    ctx = [mx.gpu(i) for i in range(num_gpus)] if num_gpus > 0 else [mx.cpu()]
    num_workers = opt.num_workers

    input_size = opt.crop_size
    model_name = opt.model
    pretrained = True if not opt.params_file else False

    kwargs = {'ctx': ctx, 'pretrained': pretrained, 'classes': classes}

    if opt.dilation > 1:
        kwargs['dilation'] = opt.dilation

    net = get_model(model_name, **kwargs)
    net.cast(opt.dtype)
    if opt.params_file:
        net.load_parameters(opt.params_file, ctx=ctx)
    else:
        net.hybridize()

    normalize = transforms.Normalize([0.485, 0.456, 0.406],
                                     [0.229, 0.224, 0.225])
    crop_ratio = opt.crop_ratio if opt.crop_ratio > 0 else 0.875
    resize = int(math.ceil(input_size / crop_ratio))

    if input_size > 320:
        transform_test = transforms.Compose([
            ToPIL(),
            ECenterCrop(input_size),
Exemplo n.º 3
0
# Get model from GluonCV model zoo
# https://gluon-cv.mxnet.io/model_zoo/index.html
kwargs = {
    'ctx': context,
    'pretrained': args.use_pretrained,
    'classes': num_classes,
    'input_size': args.input_size
}

if args.last_gamma:
    kwargs['last_gamma'] = True

if args.dropblock_prob > 0:
    kwargs['dropblock_prob'] = args.dropblock_prob

net = get_model(args.model, **kwargs)
net.cast(args.dtype)

from gluoncv.nn.dropblock import DropBlockScheduler
# does not impact normal model
drop_scheduler = DropBlockScheduler(net, 0, 0.1, args.num_epochs)

if rank == 0:
    logging.info(net)

# Create initializer
initializer = mx.init.Xavier(rnd_type='gaussian',
                             factor_type="in",
                             magnitude=2)