harryhan618 / SCNN_Pytorch

Pytorch implementation of "Spatial As Deep: Spatial CNN for Traffic Scene Understanding"
MIT License
250 stars 68 forks source link

How to change the optimizer? #34

Closed ubill88 closed 4 years ago

ubill88 commented 4 years ago

Hi, I'm a student and still very new to this field. First of all, thanks for all the works you shared! My problem is: I was trying to change the optimizer from SGD to ADAM in train.py line 66. I've also changed the cfg.file to the form that ADAM need (simply just delete the "momentum" & "nesterov"). It works just fine if I train from scratch. However, it returns a Keyerror if I want to load the .pth file you provid and resume training. File "/usr/local/lib/python3.6/dist-packages/torch/optim/adam.py", line 82, in step exp_avg, exp_avg_sq = state['exp_avg'], state['exp_avg_sq'] I found people sharing that it seems Pytorch can't change the optimizer if resuming the training process. EX: https://github.com/pytorch/pytorch/issues/7499 Is it possible that I can resume the work you train on CULane dataset, and simply just change the optimizer? Please give me some advice! Thank you very mich!

harryhan618 commented 4 years ago

It seems it's the problem of pytorch rather than my repo. Maybe you can print out the class type of the optimizer loaded from .pth file. This makes sure the type is indeed adam optimizer rather than sgd. Hope this will help.

ubill88 commented 4 years ago

@harryhan618 Thank you very much!