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

Issue when running sh test.sh #38

Open
lilyuam opened this issue Jul 12, 2023 · 1 comment
Open

Issue when running sh test.sh #38

lilyuam opened this issue Jul 12, 2023 · 1 comment

Comments

@lilyuam
Copy link

lilyuam commented Jul 12, 2023

This is my code segment in inference.py:
model = torch.load("checkpoints/model.ckpt")

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model = model.to(device)

When I run sh test.sh I get this error:
Global seed set to 321
Traceback (most recent call last):
File "scripts/inference.py", line 410, in
main()
File "scripts/inference.py", line 279, in main
model = model.to(device)
AttributeError: 'dict' object has no attribute 'to'
Global seed set to 5876
Traceback (most recent call last):
File "scripts/inference.py", line 410, in
main()
File "scripts/inference.py", line 279, in main
model = model.to(device)
AttributeError: 'dict' object has no attribute 'to'
Global seed set to 5065
Traceback (most recent call last):
File "scripts/inference.py", line 410, in
main()
File "scripts/inference.py", line 279, in main
model = model.to(device)
AttributeError: 'dict' object has no attribute 'to'

@fujistoo
Copy link

fujistoo commented Jul 13, 2023

You'd need model.load_state_dict() after loading the state dict.

state_dict = torch.load("checkpoints/model.ckpt")
model.load_state_dict(state_dict)

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

2 participants