01. PyTorch Workflow Fundamentals Timestand - 5:34:45sec #234
Unanswered
Gauravjake
asked this question in
Q&A
Replies: 2 comments
-
on line 3, try changing super().init() to super().init(), I don't know this might fix the problem but let give it a try. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey @Gauravjake , I hope you're well.
|
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.
-
here are the code and I got the error that object has no attribute 'weights'
from torch import nn
Create lines repression model class
class LinearRegressionModel(nn.Module): # -> almost everything in Pytorch inherhits from nn.Module
def init(self):
super().init()
self.weights = nn.Parameter(torch.randn(1, # <- start with a random weight and try to adjust it to the ideal weight
requires_grad=True, # <- can this parameter be updated via gradient descent?
dtype=torch.float)) # <- Pytorch loves the datatype torch float32
self.bias = nn.Parameter(torch.randn(1, #<- start with a random bias and try to adjust it to the ideal bias
require_grad=True, # <- can this parameter be update via gradient descent?
dtype=torch.float)) # <- Python loves the datatype torch.float32
Forward method to define the computation is the node:
def forward(self, x: torch.Tensor) -> torch.Tensor: # <- "x" is the input data
return self.weights * x + self.bias # this is the linear regression formula
``
AttributeError Traceback (most recent call last)
in
2 with torch.inference_mode():
3
----> 4 y_preds = model_0(x_test)
5
2 frames
/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py in getattr(self, name)
1263 if name in modules:
1264 return modules[name]
-> 1265 raise AttributeError("'{}' object has no attribute '{}'".format(
1266 type(self).name, name))
1267
AttributeError: 'LinearRegressionModel' object has no attribute 'weights'
.
Beta Was this translation helpful? Give feedback.
All reactions