MCPcopy Create free account
hub / github.com/WeChatCV/WeVisionOne / MLP

Class MLP

WeVisionOne/utils/utils.py:11–23  ·  view source on GitHub ↗

Very simple multi-layer perceptron (also called FFN)

Source from the content-addressed store, hash-verified

9
10
11class MLP(nn.Module):
12 """ Very simple multi-layer perceptron (also called FFN)"""
13
14 def __init__(self, input_dim, hidden_dim, output_dim, num_layers):
15 super().__init__()
16 self.num_layers = num_layers
17 h = [hidden_dim] * (num_layers - 1)
18 self.layers = nn.ModuleList(nn.Linear(n, k) for n, k in zip([input_dim] + h, h + [output_dim]))
19
20 def forward(self, x):
21 for i, layer in enumerate(self.layers):
22 x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
23 return x
24
25
26def inverse_sigmoid(x, eps=1e-5):

Callers 3

__init__Method · 0.50
__init__Method · 0.50
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected