示例#1
0
    assert False, 'Do not support dataset : {}'.format(args.dataset)

  
train_loader = torch.utils.data.DataLoader(train_data, batch_size=args.batch_size, shuffle=True,
                                           num_workers=args.workers, pin_memory=True)

test_loader = torch.utils.data.DataLoader(test_data, batch_size=args.batch_size, shuffle=False,
                                          num_workers=args.workers, pin_memory=True)


print("=> creating model '{}'".format(args.arch))


if args.dataset=='imagenet':    
    if args.arch=='resnet34':
        net=resnet_imagenet.resnet34(args=args)
    elif args.arch=='resnet18':
        net=resnet_imagenet.resnet18(args=args)

else:
    if args.arch=='dyresnet20':
        net=resnet_cifar.resnet20(num_classes=num_classes,args=args)
  
    elif args.arch=='dyresnet32':
        net=resnet_cifar.resnet32(num_classes=num_classes,args=args)
     
    elif args.arch=='dyresnet56':
        net=resnet_cifar.resnet56(num_classes=num_classes,args=args)

    
if args.dataset=='imagenet':
示例#2
0
文件: train.py 项目: ZLKong/Pruning
    print(
        '  **Train** Prec@1 {top1.avg:.3f} Prec@5 {top5.avg:.3f} Error@1 {error1:.3f}'
        .format(top1=top1, top5=top5, error1=100 - top1.avg), log)
    return top1.avg, losses.avg


print("=> creating model '{}'".format(args.arch))

if args.dataset == 'imagenet':

    if args.arch == 'resnet101':
        net = resnet_imagenet.resnet101()
    elif args.arch == 'resnet50':
        net = resnet_imagenet.resnet50()
    elif args.arch == 'resnet34':
        net = resnet_imagenet.resnet34()
    elif args.arch == 'resnet18':
        net = resnet_imagenet.resnet18()
else:
    if args.arch == 'resnet110':
        net = models.resnet110(num_classes=10)
    elif args.arch == 'resnet56':
        net = models.resnet56(num_classes=10)
    elif args.arch == 'resnet32':
        net = models.resnet32(num_classes=10)
    elif args.arch == 'resnet20':
        net = models.resnet20(num_classes=10)

if args.dataset == 'imagenet':

    if args.arch == 'resnet101':
示例#3
0
def load_model(opt):

    if opt.from_modelzoo:
        if opt.pretrained:
            print("=> using pre-trained model '{}'".format(opt.arch))
            model = models.__dict__[opt.model_def](pretrained=True)
        else:
            print("=> creating model '{}'".format(opt.arch))
            model = models.__dict__[opt.model_def]()

        return model
    else:
        if opt.pretrained_file != '':
            model = torch.load(opt.pretrained_filedir)
        else:
            if opt.model_def == 'alexnet':
                model = alexnet.Net()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'mobilenet':
                model = mobilenet.Net(nClasses=opt.nclasses,
                                      width_mult=opt.widthmult,
                                      gtp=opt.grouptype,
                                      gsz=opt.sp,
                                      expsz=opt.exp)
                if opt.cuda:
                    model = model.cuda()

            elif opt.model_def == 'alexnetexpander':
                model = alexnetexpander.Net()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'vgg16cifar':
                model = vggcifar.vgg16()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'vgg16cifar_bn':
                model = vggcifar.vgg16_bn()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'vgg16cifarexpander':
                model = vggcifarexpander.vgg16()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'vgg16cifar_bnexpander':
                model = vggcifarexpander.vgg16_bn()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenet_cifar':
                model = densenet_cifar.DenseNet3(opt.layers,
                                                 opt.nclasses,
                                                 opt.growth,
                                                 reduction=opt.reduce,
                                                 bottleneck=opt.bottleneck,
                                                 dropRate=opt.droprate)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenetgrouped_cifar':
                model = densenetgrouped_cifar.DenseNet3(
                    opt.layers,
                    opt.nclasses,
                    opt.growth,
                    reduction=opt.reduce,
                    bottleneck=opt.bottleneck,
                    dropRate=opt.droprate)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenetexpander_cifar':
                model = densenetexpander_cifar.DenseNet3(
                    opt.layers,
                    opt.nclasses,
                    opt.growth,
                    reduction=opt.reduce,
                    bottleneck=opt.bottleneck,
                    dropRate=opt.droprate,
                    expandSize=opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenet121':
                model = densenet.densenet121()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenet169':
                model = densenet.densenet169()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenet161':
                model = densenet.densenet161()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenet201':
                model = densenet.densenet201()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenetexpander121':
                model = densenetexpander.densenet121(expandSize=opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenetexpander169':
                model = densenetexpander.densenet169(expandSize=opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenetexpander161':
                model = densenetexpander.densenet161(expandSize=opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'densenetexpander201':
                model = densenetexpander.densenet201(expandSize=opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnet34':
                model = resnet.resnet34()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnet50':
                model = resnet.resnet50()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnet101':
                model = resnet.resnet101()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnet152':
                model = resnet.resnet152()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnetexpander34':
                model = resnetexpander.resnet34(opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnetexpander50':
                model = resnetexpander.resnet50(opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnetexpander101':
                model = resnetexpander.resnet101(opt.expandSize)
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnetexpander152':
                model = resnetexpander.resnet152(opt.expandSize)
                if opt.cuda:
                    model = model.cuda()

            elif opt.model_def == 'resnet18':
                model = resnet.resnet18()
                if opt.cuda:
                    model = model.cuda()
            elif opt.model_def == 'resnet50':
                model = resnet.resnet50()
                if opt.cuda:
                    model = model.cuda()

    return model