PyTorch Tutorial 17 - Saving and Loading Models

  Рет қаралды 72,825

Patrick Loeber

Patrick Loeber

Күн бұрын

Пікірлер: 57
@khadijakaimous3408
@khadijakaimous3408 Ай бұрын
thank you so much for these series, well explained
@user-or7ji5hv8y
@user-or7ji5hv8y 4 жыл бұрын
This is the best pytorch series I have come across. examples get right to the gist of lesson.
@patloeber
@patloeber 4 жыл бұрын
thank you!
@npomfret
@npomfret Жыл бұрын
There are a couple of mistakes at around 14:30. You are using the state from the 'checkpoint' variable, where I think you should be using state from the 'loaded_checkpoint' variable. In general, I think this part of the tutorial would be clearer if you'd used two files, one for saving and one for loading. Also, a better IDE would highlight unused variables which might have helped avoid this mistake.
@geoffreyexoo
@geoffreyexoo 3 жыл бұрын
Mr. Python Engineer does a good job, moves along at a reasonable speed.
@patloeber
@patloeber 3 жыл бұрын
Thanks, glad you like it
@christinagiannoula3106
@christinagiannoula3106 4 жыл бұрын
In 15min, lines 32 and 32 should change to "model.load_state_dict(loaded_checkpoint["model_state"])" and "optimizer.load_state_dict(checkpoint["optim_state"]), respectively.
@patloeber
@patloeber 4 жыл бұрын
Oh you are correct! Thanks for the hint!
@baotography7829
@baotography7829 4 жыл бұрын
Hi, Why not line 33 is: optimizer.load_state_dict(loaded_checkpoint["optim_state"])?
@unknown3158
@unknown3158 3 жыл бұрын
@@baotography7829 Line 33 should be as you say.
@sarahjamal86
@sarahjamal86 4 жыл бұрын
Like always beautiful video, I am giving your videos to all the beginners out there :-)
@patloeber
@patloeber 4 жыл бұрын
Thanks so much :)
@amankushwaha8927
@amankushwaha8927 2 жыл бұрын
Very helpful video. Thanks
@chiruk2835
@chiruk2835 4 жыл бұрын
Excellent and very useful, I finished all 17 tutorials, theank you
@amerel-samman9929
@amerel-samman9929 4 жыл бұрын
Every pytorch video: "and you can ignore this warning right here" :P I am going to be first to fall into that trap. Great series! Thank you so much.
@ubaidghante8604
@ubaidghante8604 2 жыл бұрын
Great video, thanks man 👍🏻
@Footballistaas
@Footballistaas 3 ай бұрын
hello, any advice how I can prep for interview for this?
@prajganesh
@prajganesh 4 жыл бұрын
Great series! it will be great if you can add more pytorch videos :)
@inesylla9706
@inesylla9706 4 жыл бұрын
thank you for the clear lesson! Really useful!
@patloeber
@patloeber 4 жыл бұрын
glad you like it!
@longdang7791
@longdang7791 Жыл бұрын
Hi, thank you for showing all the methods. I have a federated learning use-case where I train a single model using 32 clients. Currently, I have CUDA Out of memory issue. I want to know how each of the methods presented here affect the memory allocation and reservation on a single GPU. Any comment/idea is appreciate. Many thanks.
@MuhammadHussain-ws1xs
@MuhammadHussain-ws1xs 3 жыл бұрын
Amazing video, can i confirm that by using this method we can do fine tuning, for example train our model on one dataset, then save and load the model (with the weights), we can then train on a similar dataset but using the loaded model with the saved weights, right?
@iNTERnazionaleNotizia589
@iNTERnazionaleNotizia589 3 ай бұрын
Hi I want to ask, Is it possible to load a Pretrained model from other Dataset (such as BTCV or BraTS2021) , and use it for inference to a different dataset (such as ISLES 2022)?
@cyukore1796
@cyukore1796 4 жыл бұрын
very clear tutorial
@patloeber
@patloeber 4 жыл бұрын
thanks!
@bijjalanaganithin3798
@bijjalanaganithin3798 4 жыл бұрын
Thank You so much for this tutorial series
@patloeber
@patloeber 4 жыл бұрын
Glad you like it:)
@nguyenduydatnguyenduydat2640
@nguyenduydatnguyenduydat2640 3 жыл бұрын
Thank you so much for making the wonderful tutorial! Would you like to correct again the part load checkpoint. I thought the command in line 32 33 should be model.load_state_dict(loaded_checkpoint['model_state']) and optimizer.load_state_dict(loaded_checkpoint['optim_state'])
@ahmedgdoura218
@ahmedgdoura218 4 жыл бұрын
Hi, in 8:07 why we see that requires_grad=True even when you set your model to .eval() mode thanx!
@patloeber
@patloeber 4 жыл бұрын
Very good observation, sorry if I miscommunicated that! model.eval() will not deactivate the requires_grad! See here: discuss.pytorch.org/t/model-eval-vs-with-torch-no-grad/19615
@GurpreetSingh-si2gh
@GurpreetSingh-si2gh 2 жыл бұрын
Thank you very much.🙏
@shivanshchakrawarti9289
@shivanshchakrawarti9289 2 жыл бұрын
How do you save losses and accuracy in a csv file? after each epoch?
@erictian8075
@erictian8075 4 жыл бұрын
Thanks for the great video! I have a question at 14:56, when you print the loaded optimizer.state_dict(), the lr is loaded correctly, but the 'params' are not the same. What do 'params' of the optimizer mean? If I have saved checkpoint at epoch 100 and want to resume training by loading checkpoint, does the inconformity of params influence my training?
@qhliucy
@qhliucy 4 жыл бұрын
'params' are always the memory addresses of params which you used to init the optimizer and will not change when you call optimizer.load_state_dict(). The memory addresses saved in checkpoint are meaningless unless you save and then load the checkpoint in the same process. In the video, the new optimizer is inited with the new model's parameters( optimizer = torch.optim.SGD(model.parameters(), lr=0) ).
@m3dXX
@m3dXX 4 жыл бұрын
Great series, thanks for your work. Could you cover topic of NN for non-linear regression tasks with PyTorch?
@patloeber
@patloeber 4 жыл бұрын
I will consider this :)
@Sparklerated
@Sparklerated 3 жыл бұрын
could you make video about semantic segmentation with ensemble model with different encoders on pytorch, thank you!
@tehreemsyed8621
@tehreemsyed8621 4 жыл бұрын
Nice Explanation!! I trained my model on GPU and saved but when loaded my .pt file using CPU, got an error? RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0, and CPU! What should I do in this case? Thank you
@patloeber
@patloeber 4 жыл бұрын
did you use map_location? device = torch.device('cpu') model = Model(*args, **kwargs) model.load_state_dict(torch.load(PATH, map_location=device)) Also, you must push all your tensors and the model to the same device (either to cpu or gpu)
@krishj8011
@krishj8011 4 жыл бұрын
Awesome Tutorial..👍👍👍
@patloeber
@patloeber 4 жыл бұрын
Thanks :)
@mywayluna1715
@mywayluna1715 3 жыл бұрын
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.
@annemahoro9966
@annemahoro9966 3 жыл бұрын
I need your help on how I can resolve below issues: RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
@mohammadusamah819
@mohammadusamah819 2 жыл бұрын
Hi I love your videos and it has been very much help for me. I have a question that how can we use pytorch custom models on different files
@omerbinali9472
@omerbinali9472 3 жыл бұрын
How can we convert saved .pt model to .pb ?
@newajsorifnishad9169
@newajsorifnishad9169 3 жыл бұрын
Why my model run again after load. Pth file? Can u plz help me
@teetanrobotics5363
@teetanrobotics5363 4 жыл бұрын
amazing video
@innotech4079
@innotech4079 4 жыл бұрын
how to load *.pt?
@patloeber
@patloeber 4 жыл бұрын
model = torch.load(filename.pt) or model.load_state_dict(torch.load(filename.pt))
@Dr.Bimechi
@Dr.Bimechi 3 жыл бұрын
tnx
4 жыл бұрын
Hey man i have been trying to reach you out via email. I need some help with a project that i am working on. lmk if you can help me out
@ewunate
@ewunate 12 күн бұрын
Tanx
@ashwiniaditya8445
@ashwiniaditya8445 3 жыл бұрын
Your voice is irritating. Giving knowledge is one thing but that voice is distracting me from concentrating on the topic (looks like you are putting on an accent). And what is with ending each sentence like you are asking a question?
@lakeguy65616
@lakeguy65616 2 жыл бұрын
HELP! I am confused. I have created and trained a model successfully. I have saved the model using the lazy method (torch.save(model, MODEL_NAME)) ** model_name is the file name and full path. Now, in a separate file(forecast), I want to load the trained model. So in this new forecast file, I've loaded the model from disk "model = torch.load("C:\\Users\\user\\Desktop\\datasets\ ain\\model.pth") " as per the lazy method. it generates an error message AttributeError: Can't get attribute 'NeuralNet' on
@longdang7791
@longdang7791 Жыл бұрын
Do not use the lazy method. You should use the recommended ones to avoid this situation. After training is done, it is better to save the trained model and load it and do an evaluation on test data to confirm your model's prediction performance.
PYTORCH COMMON MISTAKES - How To Save Time 🕒
19:12
Aladdin Persson
Рет қаралды 56 М.
Autoencoder In PyTorch - Theory & Implementation
30:00
Patrick Loeber
Рет қаралды 73 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
6 Tips to write BETTER For Loops in Python
9:19
Patrick Loeber
Рет қаралды 251 М.
7 PyTorch Tips You Should Know
17:12
Edan Meyer
Рет қаралды 22 М.
PyTorch RNN Tutorial - Name Classification Using A Recurrent Neural Net
38:57
Top 10 Python One Liners YOU MUST KNOW!
4:52
Patrick Loeber
Рет қаралды 139 М.
The Biggest React Framework You've Never Heard of
20:29
Theo - t3․gg
Рет қаралды 51 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН