pytorch-tutorial icon indicating copy to clipboard operation
pytorch-tutorial copied to clipboard

AttributeError: module 'torch.nn' has no attribute 'linear'

Open Iwillsd opened this issue 4 years ago • 2 comments

#=============================================#

2.Basic autogard example2

#=============================================#

Create tensors of shape (10,3) and (10,2)

x = torch.randn(10, 3) y = torch.randn(10, 2)

Build a fully connected layer

linear = nn.linear(3, 2) print('w:', linear.weight) print('b:', linear.bias)

Build loss function and optimizer

loss = nn.MSELoss() optimizer = torch.optim.SGD(linear.parameters(), lr=0.01)

Please help answer this question, thank you very much!

Iwillsd avatar Aug 22 '21 08:08 Iwillsd

It's nn.Linear, with a capital L.

linear = nn.Linear(3, 2)

Yozh2 avatar Apr 05 '22 07:04 Yozh2

it's with capital L in Linear isn't it? If it's the case, I think this issue should be closed.

NourSoltani avatar Nov 23 '22 16:11 NourSoltani