-1

I hope you are well I have a question can I train transfer learning like pre-trained model 'vgg16' trained on ImageNet in my customer data and save weight to train another customer data? How I can do this, please Thanks for ur time

Asma Hekal
  • 19
  • 3

1 Answers1

0

I do example with Pytorch framework.
When you train any model, you have to define training strategy.
There are two ways to save and load trained weight for transfer learning in Pytorch.


The first is load state dict - only save and load the weight (paramemters) (recommended).
While training, if condition you defined satisfied, let's save the trained weight by this command (refer link)
torch.save(model.state_dict(), PATH)

And then when you train VGG16 model with other custom dataset and want to transfer learning from previous trained weight, use this

model = VGG16(*args, **kwargs)
model.load_state_dict(torch.load(PATH))
model.eval()

The second way is load the whole model (model structure included)
To save model, use (refer link)

torch.save(model, PATH)

And to load it

# Model class must be defined somewhere
model = torch.load(PATH)
model.eval()

You can refer some links [1], [2]

AnhPC03
  • 622
  • 5
  • 15