How to save model weights to local machine from colab?

hi guys,
i train my model for image classifier of flower dataset on colab -because it will take long time on my local machine- using pretrained model vgg19 and after train i want to save my model weights on my local machine how can i do that ?


i found this but i can’t reuse for pytorch

you can reuse the same solution for pytorch. there’s nothing about the solution that makes it specific to another framework. (you are just saving a file in a particular folder)

how can i edit this part to be proper for .pth

model_json = model.to_json()
with open("drive/app/model.json", "w") as json_file:
    json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("drive/app/model_weights.h5")
print("Saved model to drive")

replace that entire snippet with:

torch.save(model.state_dict(), 'drive/app/model.pth')
3 Likes

thanks very much it works :+1: