MCPcopy Create free account
hub / github.com/computational-imaging/bacon / MFNBase

Class MFNBase

experiments/plot_activation_distributions.py:23–58  ·  view source on GitHub ↗

Multiplicative filter network base class. Expects the child class to define the 'filters' attribute, which should be a nn.ModuleList of n_layers+1 filters with output equal to hidden_size.

Source from the content-addressed store, hash-verified

21
22# original MFN implementation
23class MFNBase(nn.Module):
24 """
25 Multiplicative filter network base class.
26 Expects the child class to define the 'filters' attribute, which should be
27 a nn.ModuleList of n_layers+1 filters with output equal to hidden_size.
28 """
29
30 def __init__(
31 self, hidden_size, out_size, n_layers, weight_scale, bias=True, output_act=False
32 ):
33 super().__init__()
34
35 self.linear = nn.ModuleList(
36 [nn.Linear(hidden_size, hidden_size, bias) for _ in range(n_layers)]
37 )
38 self.output_linear = nn.Linear(hidden_size, out_size)
39 self.output_act = output_act
40
41 for lin in self.linear:
42 lin.weight.data.uniform_(
43 -np.sqrt(weight_scale / hidden_size),
44 np.sqrt(weight_scale / hidden_size),
45 )
46
47 return
48
49 def forward(self, x):
50 out = self.filters[0](x)
51 for i in range(1, len(self.filters)):
52 out = self.filters[i](x) * self.linear[i - 1](out)
53 out = self.output_linear(out)
54
55 if self.output_act:
56 out = torch.sin(out)
57
58 return out
59
60
61class FourierLayer(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected