Replies: 2 comments
-
Are you trying to view your model's weights and biases? If so, I think you need to use the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, using state_dict() can work. I also do not understand that next() function can iterate over all the parameters, but why I can only get the weights? I think if I use next() method twice, I can get weights and bias also.
…________________________________
From: Chris Adamo ***@***.***>
Sent: Tuesday, May 9, 2023 10:30 PM
To: mrdbourke/pytorch-deep-learning ***@***.***>
Cc: Zhang, Joe ***@***.***>; Author ***@***.***>
Subject: Re: [mrdbourke/pytorch-deep-learning] About next(model.parameters()) (Discussion #439)
Are you trying to view your model's weights and biases? If so, I think you need to use the state_dict() method.
—
Reply to this email directly, view it on GitHub<#439 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A4FGLFDGX5RLH7JHRZGTZP3XFKSNNANCNFSM6AAAAAAXYFBFSU>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
torch.manual_seed(42)
model_1 = LinearRegressionModel()
model_1, model_1.state_dict()
OUTPUT:
(LinearRegressionModel(),
OrderedDict([('weights', tensor([0.1940], device='cuda:0')),
('bias', tensor([0.1391], device='cuda:0'))]))
next(model_1.parameters()).device
p1 = next(model_1.parameters())
p2 = next(model_1.parameters())
print(f"There are the params {p1}, {p2}")
print(type(model_1.parameters()))
OUTPUT:
There are the params Parameter containing:
tensor([0.1940], device='cuda:0', requires_grad=True), Parameter containing:
tensor([0.1940], device='cuda:0', requires_grad=True)
<class 'generator'>
Why I cannot get bias using p2 = next(model_1.parameters())?
next function can be used for every object class in pytorch?
Beta Was this translation helpful? Give feedback.
All reactions