Serializes the network object to disk. :param file_name: Path to store serialized network object on disk. **Example:** .. code-block:: python import torch import matplotlib.pyplot as plt from pathlib import Path
(self, file_name: str)
| 161 | monitor.dt = self.dt |
| 162 | |
| 163 | def save(self, file_name: str) -> None: |
| 164 | # language=rst |
| 165 | """ |
| 166 | Serializes the network object to disk. |
| 167 | |
| 168 | :param file_name: Path to store serialized network object on disk. |
| 169 | |
| 170 | **Example:** |
| 171 | |
| 172 | .. code-block:: python |
| 173 | |
| 174 | import torch |
| 175 | import matplotlib.pyplot as plt |
| 176 | |
| 177 | from pathlib import Path |
| 178 | from bindsnet.network import * |
| 179 | from bindsnet.network import topology |
| 180 | |
| 181 | # Build simple network. |
| 182 | network = Network(dt=1.0) |
| 183 | |
| 184 | X = nodes.Input(100) # Input layer. |
| 185 | Y = nodes.LIFNodes(100) # Layer of LIF neurons. |
| 186 | C = topology.Connection(source=X, target=Y, w=torch.rand(X.n, Y.n)) # Connection from X to Y. |
| 187 | |
| 188 | # Add everything to the network object. |
| 189 | network.add_layer(layer=X, name='X') |
| 190 | network.add_layer(layer=Y, name='Y') |
| 191 | network.add_connection(connection=C, source='X', target='Y') |
| 192 | |
| 193 | # Save the network to disk. |
| 194 | network.save(str(Path.home()) + '/network.pt') |
| 195 | """ |
| 196 | torch.serialization.add_safe_globals([self]) |
| 197 | torch.save(self, open(file_name, "wb")) |
| 198 | |
| 199 | def clone(self) -> "Network": |
| 200 | # language=rst |
no outgoing calls