| 1528 | |
| 1529 | class TorchFCLayer(nn.Module): |
| 1530 | def __init__(self, n_in, n_hid, act_fn, params, **kwargs): |
| 1531 | super(TorchFCLayer, self).__init__() |
| 1532 | self.layer1 = nn.Linear(n_in, n_hid) |
| 1533 | |
| 1534 | # explicitly set weights and bias |
| 1535 | # NB: we pass the *transpose* of the weights to pytorch, meaning |
| 1536 | # we'll need to check against the *transpose* of our outputs for |
| 1537 | # any function of the weights |
| 1538 | self.layer1.weight = nn.Parameter(torch.FloatTensor(params["W"].T)) |
| 1539 | self.layer1.bias = nn.Parameter(torch.FloatTensor(params["b"])) |
| 1540 | |
| 1541 | self.act_fn = act_fn |
| 1542 | self.model = nn.Sequential(self.layer1, self.act_fn) |
| 1543 | |
| 1544 | def forward(self, X): |
| 1545 | self.X = X |