How to save and load models in Pytorch

preview_player
Показать описание
Let's say you have a model that is working but now you want to be able to save a checkpoint and load it to continue training at a later point. In this video I walkthrough an example of how to do it!

❤️ Support the channel ❤️

Paid Courses I recommend for learning (affiliate links, no extra cost for you):

✨ Free Resources that are great:

💻 My Deep Learning Setup and Recording Setup:

GitHub Repository:

✅ One-Time Donations:

▶️ You Can Connect with me on:
Рекомендации по теме
Комментарии
Автор

Good day sir. Thanks for your video.
I have made my model using pytorch (its a seq2seq model)
However the files are large, please how can I save and load the weights to use it for production? Thank you

kyomdonalddogo
Автор

How can I use the saved checkpoint for deployment to the production? For example: I want to use the checkpoint for classifying text for sentiment analysis

shubheshswain
Автор

Great Video!
I have a small question though. Is it mandatory to save the optimizer?

sparta-iqgj
Автор

hi, i trained my model for task agnostic meta learning algorithm and it generated 10 .pth.tar extension files . I want to design a object detection model using this created models but i am unable to do it, can you please help me

akshaysonawane
Автор

Thank you so much for your lecture! I tried to save all my testing model result with nii(image) format. Could you give me a tip for me? I saved and loaded model to test. I did the image segmentation, my goal is to get a predicted segmentation images.

mywayluna
Автор

Hi . Can you please make a video about pruning and quantization?

iversonvarun
Автор

@Aladdin Persson i want to convert my ckpt file to readable form. How can i achieve this??

cebthjy
Автор

Thank you so much! The best video in YouTube to save models in PyTorch. Just two questions,
1. apart from epoch, model state and optimizer state, what else should I save to reproduce the exact same results.
2. Why so people save loss? When you load the model, it is automatically starting from where it stopped in the loss right?
Thank you again!

madhxxx
Автор

awesome stuff. I think not saving the optimizer can the reason my loss goes up after loading from file subsequent training

rotorblade
Автор

I would like to decrease the size of my model. Is it possible?

deidy
Автор

Hi, thanks for the video. I have a quick question: if I want to save the model after training, to be used only for inference in the future and not further training, do I do it the same way as shown here?

canernm
Автор

Hi, any idea how i can write a function to determine if either my training loss or validation loss is lower, and save that loss to checkpoint within class. With the train and validation defined as a function

ripleylee
Автор

After load, how can I predict? I got error

AttributeError: 'DataLoader' object has no attribute 'size'

while trying to predict the test_loader

joxa
Автор

I saved pt file to not create NN form.... just load file only like KERAS, but it fail to loaded.. how to load only pt file?

innotech
Автор

Thanks, but one doubt is when we want to use our models in some other file then we have to write whole code of model and then update its parameters from the file where we have stored, Is there any other way where we can directly use model and use it to predict the outcome ?

avshek_ps
Автор

Hey Aladdin, instead of checkpoints, wouldn't it be better to use model.fit(callbacks) where in callbacks we can have EarlyStopping and ModelCheckpoint() option. I know it's there in keras, but is there a similar thing in PyTorch?

ShashankShuklaBIS
Автор

Can you also show how to use the saved model and run predictions?

shayanlameh
Автор

Thank you for the great video. To me, it would be more simpler if you just embedded the saving and loading commands inside the code directly, without creating additional functions :)

Malik-bxqg
Автор

I just noticed the BCE Loss in the intro lol

prabhavkaula
Автор

Why does line 50 say model = CNN when it isn't a CNN?

sepgorut