Fetches outputs from network layers to use as input to downstream layers. :param layers: Layers to update inputs for. Defaults to all network layers. :return: Inputs to all layers for the current iteration.
(self, layers: Iterable = None)
| 209 | return torch.load(virtual_file) |
| 210 | |
| 211 | def _get_inputs(self, layers: Iterable = None) -> Dict[str, torch.Tensor]: |
| 212 | # language=rst |
| 213 | """ |
| 214 | Fetches outputs from network layers to use as input to downstream layers. |
| 215 | |
| 216 | :param layers: Layers to update inputs for. Defaults to all network layers. |
| 217 | :return: Inputs to all layers for the current iteration. |
| 218 | """ |
| 219 | inputs = {} |
| 220 | |
| 221 | if layers is None: |
| 222 | layers = self.layers |
| 223 | |
| 224 | # Loop over network connections. |
| 225 | for c in self.connections: |
| 226 | if c[1] in layers: |
| 227 | # Fetch source and target populations. |
| 228 | source = self.connections[c].source |
| 229 | target = self.connections[c].target |
| 230 | |
| 231 | if not c[1] in inputs: |
| 232 | if isinstance(target, CSRMNodes): |
| 233 | inputs[c[1]] = torch.zeros( |
| 234 | self.batch_size, |
| 235 | target.res_window_size, |
| 236 | *target.shape, |
| 237 | device=target.s.device, |
| 238 | ) |
| 239 | else: |
| 240 | inputs[c[1]] = torch.zeros( |
| 241 | self.batch_size, *target.shape, device=target.s.device |
| 242 | ) |
| 243 | |
| 244 | # Add to input: source's spikes multiplied by connection weights. |
| 245 | if isinstance(target, CSRMNodes): |
| 246 | inputs[c[1]] += self.connections[c].compute_window(source.s) |
| 247 | else: |
| 248 | inputs[c[1]] += self.connections[c].compute(source.s) |
| 249 | |
| 250 | return inputs |
| 251 | |
| 252 | def run( |
| 253 | self, inputs: Dict[str, torch.Tensor], time: int, one_step=False, **kwargs |
no test coverage detected