| 175 | return torch.from_numpy(L) |
| 176 | |
| 177 | def mask_weights(self, layer,mask,mshape): |
| 178 | assert isinstance(layer, nn.Linear), 'masked layer must be linear layer' |
| 179 | |
| 180 | output_size, input_size = layer.weight.shape # pytorch weights [output_channel, input_channel] |
| 181 | input_size, output_size = int(input_size), int(output_size) |
| 182 | assert input_size % mshape == 0 and output_size % mshape == 0 |
| 183 | in_F = int(input_size / mshape) |
| 184 | out_F = int(output_size / mshape) |
| 185 | weights = layer.weight.data.view([mshape, out_F, mshape, in_F]) |
| 186 | weights.mul_(mask.t().view(mshape, 1, mshape, 1).to(device=weights.get_device())) |
| 187 | |
| 188 | def get_local_feature(self, xinj, fmap): |
| 189 | bs = fmap.shape[0] |