big_transfer icon indicating copy to clipboard operation
big_transfer copied to clipboard

Saving model after finetuning

Open sahilwalke17 opened this issue 5 years ago • 4 comments

How do I save the model after fine-tuning using command line on dataset(CIFAR100) ?

sahilwalke17 avatar Aug 08 '20 14:08 sahilwalke17

you gotta edit a line in train.py. In the PyTorch scripts, apparently the block that calls torch.save only gets executed when you enable the eval_every flag.

you can add this line torch.save at the end of the training so that it saves one final time before it finishes training

    # Final eval at end of training. and save model?
    run_eval(model, valid_loader, device, chrono, logger, step='end')
    torch.save({
                "step": step,
                "model": model.state_dict(),
                "optim" : optim.state_dict(),
            }, savename)

sickerin avatar Aug 31 '20 09:08 sickerin

thx. this saved as a tar file, which contains a set of files. should it be a simple pt file?

charliewang789 avatar Sep 26 '20 17:09 charliewang789

I did as skcerin said. But failed to load to train, it says "expected cpu but got cuda:0"

tianrengao avatar Oct 11 '20 10:10 tianrengao

you gotta edit a line in train.py. In the PyTorch scripts, apparently the block that calls torch.save only gets executed when you enable the eval_every flag.

you can add this line torch.save at the end of the training so that it saves one final time before it finishes training

    # Final eval at end of training. and save model?
    run_eval(model, valid_loader, device, chrono, logger, step='end')
    torch.save({
                "step": step,
                "model": model.state_dict(),
                "optim" : optim.state_dict(),
            }, savename)

how can use it? for test

kyuhong0206 avatar Mar 04 '21 07:03 kyuhong0206