Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 93b3b14

Browse files
author
HP Z4 G4
committed
init
1 parent 6102cf6 commit 93b3b14

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎example0221.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import torch
2+
import torch.nn as nn
3+
4+
class LinearModel(nn.Module):
5+
def __init__(self, ndim):
6+
super(LinearModel, self).__init__()
7+
self.ndim = ndim
8+
9+
self.weight = nn.Parameter(torch.randn(ndim, 1))
10+
self.bias = nn.Parameter(torch.randn(1))
11+
12+
def forward(self, x):
13+
return x.mm(self.weight) + self.bias
14+
15+
lm = LinearModel(5)
16+
x = torch.randn(4, 5)
17+
18+
print(x)
19+
print(lm(x))
20+
21+
print(list(lm.named_parameters()))
22+
print(list(lm.parameters()))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /