netlite 0.0.4__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: netlite
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A small white-box training framework for neural networks for education.
5
5
  Project-URL: Homepage, https://github.com/haho12/netlite
6
6
  Project-URL: Issues, https://github.com/haho12/netlite/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "netlite"
7
- version = "0.0.4"
7
+ version = "0.0.5"
8
8
  authors = [
9
9
  { name="Hanno Homann", email="hanno.homann@example.com" },
10
10
  ]
@@ -12,10 +12,7 @@ from .dataloader_mnist import *
12
12
  from .dataloader_cifar10 import *
13
13
 
14
14
  # set nl.__version__
15
- try:
16
- from importlib.metadata import version, PackageNotFoundError
17
- except ImportError: # for Python < 3.8
18
- from importlib_metadata import version, PackageNotFoundError
15
+ from importlib.metadata import version, PackageNotFoundError
19
16
  try:
20
17
  __version__ = version("netlite") # get version from pyproject.toml
21
18
  except PackageNotFoundError:
@@ -271,6 +271,7 @@ class BatchNorm(Layer):
271
271
  x_out = (X - self.running_mean) / np.sqrt(self.running_var + self.eps)
272
272
  else:
273
273
  # Use running averages at inference
274
+ assert hasattr(self, 'running_var'), 'BatchNorm must be called in training-mode first.'
274
275
  x_out = (X - self.running_mean) / np.sqrt(self.running_var + self.eps)
275
276
 
276
277
  return x_out
@@ -44,4 +44,19 @@ class NeuralNetwork():
44
44
  Xin = np.zeros(input_shape, dtype='f')
45
45
  for layer in self.layers:
46
46
  Xin = layer.print(Xin)
47
-
47
+
48
+ def save(self, filename):
49
+ model = {}
50
+ for i, layer in enumerate(self.layers):
51
+ weights = layer.get_weights()
52
+ model[i] = weights
53
+ np.save(filename, model)
54
+
55
+ def load(self, filename):
56
+ loaded_params = np.load(filename, allow_pickle=True).item()
57
+ assert len(loaded_params) == len(self.layers), f'Error: Unexpected number of layers in file {filename}.'
58
+ for i, layer in enumerate(self.layers):
59
+ weights = layer.get_weights()
60
+ for key in weights:
61
+ assert key in loaded_params[i].keys(), f'Error: Key {key} no found in layer {i} of file {filename}.'
62
+ weights[key] = loaded_params[i][key]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes