| 100 | |
| 101 | |
| 102 | class MFNBase(nn.Module): |
| 103 | |
| 104 | def __init__(self, hidden_size, out_size, n_layers, weight_scale, |
| 105 | bias=True, output_act=False): |
| 106 | super().__init__() |
| 107 | |
| 108 | self.linear = nn.ModuleList( |
| 109 | [nn.Linear(hidden_size, hidden_size, bias) for _ in range(n_layers)] |
| 110 | ) |
| 111 | |
| 112 | self.output_linear = nn.Linear(hidden_size, out_size) |
| 113 | |
| 114 | self.output_act = output_act |
| 115 | |
| 116 | self.linear.apply(mfn_weights_init) |
| 117 | self.output_linear.apply(mfn_weights_init) |
| 118 | |
| 119 | def forward(self, model_input): |
| 120 | |
| 121 | input_dict = {key: input.clone().detach().requires_grad_(True) |
| 122 | for key, input in model_input.items()} |
| 123 | coords = input_dict['coords'] |
| 124 | |
| 125 | out = self.filters[0](coords) |
| 126 | for i in range(1, len(self.filters)): |
| 127 | out = self.filters[i](coords) * self.linear[i - 1](out) |
| 128 | out = self.output_linear(out) |
| 129 | |
| 130 | if self.output_act: |
| 131 | out = torch.sin(out) |
| 132 | |
| 133 | return {'model_in': input_dict, 'model_out': {'output': out}} |
| 134 | |
| 135 | |
| 136 | class FourierLayer(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected