コード例 #1
0
def set_model(args, n_data):
    # set the model
    if args.model == 'alexnet':
        if args.view == 'Lab':
            model = alexnet(in_channel=(1, 2), feat_dim=args.feat_dim)
        elif args.view == 'Rot':
            model = alexnet(in_channel=(3, 3), feat_dim=args.feat_dim)
        elif args.view == 'LabRot':
            model = alexnet(in_channel=(1, 2), feat_dim=args.feat_dim)
        else:
            raise NotImplemented('view not implemented {}'.format(args.view))

    elif args.model.startswith('resnet'):
        model = ResNetV2(args.model)
    else:
        raise ValueError('model not supported yet {}'.format(args.model))
    contrast = NCEAverage(args.feat_dim, n_data, args.nce_k, args.nce_t,
                          args.nce_m)
    criterion_l = NCECriterion(n_data)
    criterion_ab = NCECriterion(n_data)

    if torch.cuda.is_available():
        if torch.cuda.device_count() > 1:
            model = torch.nn.DataParallel(model).cuda()
        else:
            model = model.cuda()
        contrast = contrast.cuda()
        criterion_ab = criterion_ab.cuda()
        criterion_l = criterion_l.cuda()
        cudnn.benchmark = True

    return model, contrast, criterion_ab, criterion_l
コード例 #2
0
ファイル: test.py プロジェクト: coriverchen/SAT
def set_model(n_data):
    contrast = NCEAverage(128, n_data, 4096, 0.1, 0.5)
    criterion_l = NCECriterion(n_data)
    criterion_ab = NCECriterion(n_data)

    if torch.cuda.is_available():
        contrast = contrast.cuda()
        criterion_ab = criterion_ab.cuda()
        criterion_l = criterion_l.cuda()
        cudnn.benchmark = True

    return contrast, criterion_ab, criterion_l
コード例 #3
0
def set_model(args, n_data):
    # set the model
    if args.model == 'alexnet':
        model = alexnet(args.feat_dim)
    else:
        raise ValueError('model not supported yet {}'.format(args.model))
    contrast = NCEAverage(args.feat_dim, n_data, args.nce_k, args.nce_t,
                          args.nce_m)
    criterion_l = NCECriterion(n_data)
    criterion_ab = NCECriterion(n_data)

    if torch.cuda.is_available():
        model = model.cuda()
        contrast = contrast.cuda()
        criterion_ab = criterion_ab.cuda()
        criterion_l = criterion_l.cuda()
        cudnn.benchmark = True

    return model, contrast, criterion_ab, criterion_l
コード例 #4
0
ファイル: train_CMC.py プロジェクト: amsword/CMC
def set_model(args, n_data):
    # set the model
    if args.model == 'alexnet':
        model = MyAlexNetCMC(args.feat_dim)
    elif args.model.startswith('resnet'):
        model = MyResNetsCMC(args.model)
    else:
        raise ValueError('model not supported yet {}'.format(args.model))

    contrast = NCEAverage(args.feat_dim, n_data, args.nce_k, args.nce_t, args.nce_m, args.softmax)
    criterion_l = NCESoftmaxLoss() if args.softmax else NCECriterion(n_data)
    criterion_ab = NCESoftmaxLoss() if args.softmax else NCECriterion(n_data)

    if torch.cuda.is_available():
        model = model.cuda()
        contrast = contrast.cuda()
        criterion_ab = criterion_ab.cuda()
        criterion_l = criterion_l.cuda()
        cudnn.benchmark = True

    return model, contrast, criterion_ab, criterion_l