示例#1
0
def main():
    model = VGG(depth=16, init_weights=True, cfg=None)
    # model = VGG_shaokai("vgg16")
    # model = ConvNet()
    # model = ResNet18()
    # model = torch.nn.DataParallel(model)
    model.load_state_dict(torch.load("./model_pruned/2019-04-09 11:14:52.016169/column-filter-fivelabels-masked_retrain/cifar10_vgg16_retrained_acc_93.960_4rhos_config_vgg16_v2.yaml.pt"))
    model.cuda()

    criterion = F.cross_entropy
#    criterion = CrossEntropyLossMaybeSmooth(smooth_eps=0).cuda()
    validate(test_loader, criterion, model)
    # test(model, criterion, test_loader)
    print("\n------------------------------\n")


    print('here')
    for name, weight in model.named_parameters():
        if (len(weight.size()) == 4 and "shortcut" not in name):
            print(name, weight.size())


    print('here now')
    test_column_sparsity(model)
    # test_chanel_sparsity(model)
    test_filter_sparsity(model)
示例#2
0
classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse',
           'ship', 'truck')

# Model
print('==> Building model..')
net = VGG('VGG13', n)
net = net.to(device)
if device == 'cuda':
    net = torch.nn.DataParallel(net)
    cudnn.benchmark = True

# calculate total number of threshold parameters

no_thresh_p = 0
for name, p in net.named_parameters():
    check = name.split('.')[-1]
    if check == 'thresh':
        no_thresh_p += p.numel()

lam = 1 / no_thresh_p

criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(),
                      lr=args.lr,
                      momentum=0.9,
                      weight_decay=5e-4)
scheduler = CyclicLR(optimizer)

if args.resume:
    # Load checkpoint.