pytorch-slimming icon indicating copy to clipboard operation
pytorch-slimming copied to clipboard

model size after finetuning

Open kaishijeng opened this issue 7 years ago • 10 comments

@foolwood

I noticed model size after finetuning is the same as the original model size. Shouldn't the size be the same as the pruned model?

Thanks,

kaishijeng avatar Feb 25 '18 17:02 kaishijeng

I meet the same problem as yours, and I solved it by clearing the pycache, and I hope it will help you~

angelamin avatar Mar 20 '18 11:03 angelamin

I can get this, the pruned model size is 9.3M which is not 2.2M? @angelamin @kaishijeng is it same as your model? image

MrLinNing avatar May 02 '18 12:05 MrLinNing

emmm, after I run 'python main.py -sr --s 0.0001', my checkpoint.pth.tar is 153M... Can you help me? Thanks.

RichardMrLu avatar Jun 28 '18 00:06 RichardMrLu

And it didn't save model_best.pth.tar...

RichardMrLu avatar Jun 28 '18 01:06 RichardMrLu

I check it, because of pytorch0.4, after test,type(prec1) is Tensor, so change it to type int. But models are still 153M....

RichardMrLu avatar Jun 28 '18 02:06 RichardMrLu

@MrLinNing Hello, I only change dataset's path to own Cifar10, how do you save so small model? Thanks for your help.

RichardMrLu avatar Jun 28 '18 02:06 RichardMrLu

Parameters are 20M, so model size should be (20x1000000x32)/(1024x1024x8)=76.29M soga

RichardMrLu avatar Jun 28 '18 08:06 RichardMrLu

@RichardMrLu : how did you run the script with version 0.4? Can you share your changes?

Coderx7 avatar Jul 01 '18 03:07 Coderx7

@Coderx7 def test(): model.eval() test_loss = 0 correct = 0 for data, target in test_loader: if args.cuda: data, target = data.cuda(), target.cuda() data, target = Variable(data, volatile=True), Variable(target) output = model(data) test_loss += F.cross_entropy(output, target, size_average=False).data[0] # sum up batch loss pred = output.data.max(1, keepdim=True)[1] # get the index of the max log-probability correct += pred.eq(target.data.view_as(pred)).cpu().sum()

test_loss /= len(test_loader.dataset)
print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.1f}%)\n'.format(
    test_loss, correct, len(test_loader.dataset),
    100. * correct / len(test_loader.dataset)))
return 100. * correct / len(test_loader.dataset)

def save_checkpoint(state, is_best, filename='checkpoint.pth.tar'): torch.save(state, filename) if is_best: shutil.copyfile(filename, 'model_best.pth.tar')

best_prec1 = 0. print(model) for epoch in range(args.start_epoch, args.epochs): if epoch in [args.epochs0.5, args.epochs0.75]: for param_group in optimizer.param_groups: param_group['lr'] *= 0.1 train(epoch) prec1 = test() is_best = int(prec1) > best_prec1 best_prec1 = max(int(prec1), int(best_prec1)) save_checkpoint({ 'epoch': epoch + 1, 'state_dict': model.state_dict(), 'best_prec1': best_prec1, 'optimizer': optimizer.state_dict(), }, is_best)

RichardMrLu avatar Jul 06 '18 07:07 RichardMrLu

@RichardMrLu My original model is 160M . Why our models such big with only 20M parameters?

helloelliot avatar Jun 04 '19 03:06 helloelliot