MCPcopy Index your code
hub / github.com/pytorch/tutorials / Net

Class Net

intermediate_source/visualizing_gradients_tutorial.py:65–87  ·  view source on GitHub ↗

Define a network that has num_layers of linear->norm->sigmoid transformations

Source from the content-addressed store, hash-verified

63 return nn.Sequential(nn.Linear(in_size, out_size), norm_layer(out_size), nn.Sigmoid())
64
65class Net(nn.Module):
66 """Define a network that has num_layers of linear->norm->sigmoid transformations"""
67 def __init__(self, in_size=28*28, hidden_size=128,
68 out_size=10, num_layers=3, batchnorm=False):
69 super().__init__()
70 if batchnorm is False:
71 norm_layer = nn.Identity
72 else:
73 norm_layer = nn.BatchNorm1d
74
75 layers = []
76 layers.append(fc_layer(in_size, hidden_size, norm_layer))
77
78 for i in range(num_layers-1):
79 layers.append(fc_layer(hidden_size, hidden_size, norm_layer))
80
81 layers.append(nn.Linear(hidden_size, out_size))
82
83 self.layers = nn.Sequential(*layers)
84
85 def forward(self, x):
86 x = torch.flatten(x, 1)
87 return self.layers(x)
88
89
90######################################################################

Calls

no outgoing calls

Tested by

no test coverage detected