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

Class MLP

WeVisionOne/pixel_decoder/groundingdino/utils.py:137–151  ·  view source on GitHub ↗

Very simple multi-layer perceptron (also called FFN)

Source from the content-addressed store, hash-verified

135
136
137class MLP(nn.Module):
138 """Very simple multi-layer perceptron (also called FFN)"""
139
140 def __init__(self, input_dim, hidden_dim, output_dim, num_layers):
141 super().__init__()
142 self.num_layers = num_layers
143 h = [hidden_dim] * (num_layers - 1)
144 self.layers = nn.ModuleList(
145 nn.Linear(n, k) for n, k in zip([input_dim] + h, h + [output_dim])
146 )
147
148 def forward(self, x):
149 for i, layer in enumerate(self.layers):
150 x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
151 return x
152
153
154def _get_activation_fn(activation, d_model=256, batch_dim=0):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected