Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: optimizer got an empty parameter list #6

Open
eeric opened this issue Jan 9, 2019 · 5 comments
Open

ValueError: optimizer got an empty parameter list #6

eeric opened this issue Jan 9, 2019 · 5 comments

Comments

@eeric
Copy link

eeric commented Jan 9, 2019

LeNet model used,
Traceback (most recent call last):
File "main.py", line 155, in
optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum)
File "/usr/local/lib/python3.6/dist-packages/torch/optim/sgd.py", line 64, in init
super(SGD, self).init(params, defaults)
File "/usr/local/lib/python3.6/dist-packages/torch/optim/optimizer.py", line 38, in init
raise ValueError("optimizer got an empty parameter list")
ValueError: optimizer got an empty parameter list

why?

@danieltan07
Copy link
Owner

@eeric I am not sure. May I ask what version of pytorch you are using. It works fine on mine.

@hansbu
Copy link

hansbu commented Mar 1, 2019

it should be:
optimizer = optim.SGD(model.params(), lr=args.lr, momentum=args.momentum)

use model.params() instead of model.parameters()

@hackershi
Copy link

hackershi commented Jul 8, 2019

model.params() works, but why, what's the difference

@LindgeW
Copy link

LindgeW commented Aug 30, 2021

If Adam optimizer is used, how to change ? @hansbu @hackershi @danieltan07

@Sean-asc
Copy link

Sean-asc commented Jun 2, 2022

Got the same problem. If Adam optimizer is used, how to change ? @hansbu @hackershi @danieltan07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants