netlite 1.0.0__tar.gz → 1.0.2__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.
Files changed (28) hide show
  1. {netlite-1.0.0 → netlite-1.0.2}/PKG-INFO +1 -1
  2. {netlite-1.0.0 → netlite-1.0.2}/examples/netlite_example_lenet_mnist.py +4 -0
  3. netlite-1.0.2/package_build.py +34 -0
  4. netlite-1.0.2/package_run_tests.py +11 -0
  5. netlite-1.0.2/package_upload.py +77 -0
  6. {netlite-1.0.0 → netlite-1.0.2}/pyproject.toml +1 -1
  7. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/layers.py +6 -5
  8. netlite-1.0.0/package_build.sh +0 -3
  9. netlite-1.0.0/package_run_tests.sh +0 -1
  10. netlite-1.0.0/package_upload.sh +0 -1
  11. {netlite-1.0.0 → netlite-1.0.2}/.gitignore +0 -0
  12. {netlite-1.0.0 → netlite-1.0.2}/LICENSE +0 -0
  13. {netlite-1.0.0 → netlite-1.0.2}/README.md +0 -0
  14. {netlite-1.0.0 → netlite-1.0.2}/examples/netlite_example_fit_regression_line.py +0 -0
  15. {netlite-1.0.0 → netlite-1.0.2}/examples/netlite_example_lenet_cifar10.py +0 -0
  16. {netlite-1.0.0 → netlite-1.0.2}/examples/netlite_example_xor_classifier.py +0 -0
  17. {netlite-1.0.0 → netlite-1.0.2}/images/lenet_mnist_acc_curves.svg +0 -0
  18. {netlite-1.0.0 → netlite-1.0.2}/images/logo_netlite.png +0 -0
  19. {netlite-1.0.0 → netlite-1.0.2}/requirements.txt +0 -0
  20. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/__init__.py +0 -0
  21. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/dataloader_cifar10.py +0 -0
  22. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/dataloader_mnist.py +0 -0
  23. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/loss_functions.py +0 -0
  24. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/neural_network.py +0 -0
  25. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/numba_optional.py +0 -0
  26. {netlite-1.0.0 → netlite-1.0.2}/src/netlite/optimizer.py +0 -0
  27. {netlite-1.0.0 → netlite-1.0.2}/tests/test_convolution.py +0 -0
  28. {netlite-1.0.0 → netlite-1.0.2}/tests/test_netlite.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: netlite
3
- Version: 1.0.0
3
+ Version: 1.0.2
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
@@ -1,6 +1,7 @@
1
1
  import numpy as np
2
2
  import time
3
3
  import matplotlib.pyplot as plt
4
+ from matplotlib.ticker import MaxNLocator
4
5
  import sys
5
6
  import os
6
7
 
@@ -94,6 +95,7 @@ plt.xlabel('epoch')
94
95
  plt.ylabel('loss')
95
96
  plt.title('Training LeNet on MNIST data')
96
97
  plt.grid()
98
+ plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True)) # force integer
97
99
  plt.show()
98
100
 
99
101
  plt.plot(log['acc_train'], label='training')
@@ -103,6 +105,8 @@ plt.xlabel('epoch')
103
105
  plt.ylabel('accuracy')
104
106
  plt.title('Training LeNet on MNIST data')
105
107
  plt.grid()
108
+ plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True)) # force integer
106
109
  #plt.savefig("lenet_mnist_acc_curves.svg")
110
+
107
111
  plt.show()
108
112
 
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env python
2
+ import tomllib
3
+ import requests
4
+ from packaging.version import Version
5
+ import sys
6
+ import subprocess
7
+
8
+ def build_package(require_new_version=True):
9
+ PACKAGE_NAME = "netlite"
10
+
11
+ # 1. Read local version from pyproject.toml
12
+ with open("pyproject.toml", "rb") as f:
13
+ pyproject = tomllib.load(f)
14
+
15
+ local_version = pyproject["project"]["version"]
16
+
17
+ # 2. Get latest version from PyPI
18
+ url = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
19
+ pypi_version = requests.get(url, timeout=10).json()["info"]["version"]
20
+
21
+ # 3. Compare
22
+ print("version in pyproject.toml: ", local_version)
23
+ print("version on pypi.org: ", pypi_version)
24
+ if Version(local_version) <= Version(pypi_version) and require_new_version:
25
+ print("Error: Local version must be increased for a new build")
26
+ return False
27
+
28
+ subprocess.run(['rm', '-rf', 'dist'])
29
+ subprocess.run(['python', '-m', 'build'])
30
+
31
+ return True
32
+
33
+ if __name__ == '__main__':
34
+ build_package(require_new_version=False)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env python
2
+ import subprocess
3
+ import sys
4
+
5
+ def run_tests():
6
+ result = subprocess.run([sys.executable, "-m", "pytest", "tests/", "-v"]) # ensures python interpreter in venv
7
+ return result.returncode == 0
8
+
9
+ if __name__ == '__main__':
10
+ success = run_tests()
11
+ print("Tests passed:", success)
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python
2
+ import tomllib
3
+ import requests
4
+ from packaging.version import Version
5
+ import sys
6
+ import subprocess
7
+
8
+ from package_run_tests import run_tests
9
+ from package_build import build_package
10
+
11
+ PACKAGE_NAME = "netlite"
12
+
13
+ # Steps:
14
+ # - run pytest
15
+ # - build (with new release number)
16
+ # - push to github (with release tag)
17
+ # - upload to pipy
18
+
19
+ def git_tag_and_push():
20
+ # Check code is fully committed in git
21
+ status = subprocess.run(
22
+ ["git", "status", "--porcelain"],
23
+ capture_output=True,
24
+ text=True,
25
+ check=True
26
+ ).stdout.strip()
27
+
28
+ if status:
29
+ print("Error: Working tree is dirty. Commit or stash your changes first.")
30
+ print(status)
31
+ return False
32
+
33
+ subprocess.run(['git', 'push']) # push commits
34
+
35
+ # 1. Read local version from pyproject.toml
36
+ with open("pyproject.toml", "rb") as f:
37
+ pyproject = tomllib.load(f)
38
+
39
+ local_version = pyproject["project"]["version"]
40
+
41
+ # 2. Get latest version from PyPI
42
+ #url = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
43
+ #pypi_version = requests.get(url, timeout=10).json()["info"]["version"]
44
+
45
+ # 3. Get latest git tag
46
+ git_tag = subprocess.run(
47
+ ["git", "describe", "--tags", "--abbrev=0"],
48
+ capture_output=True,
49
+ text=True,
50
+ check=True
51
+ ).stdout.strip()
52
+ # strip leading "v" (v1.2.3 → 1.2.3)
53
+ git_version = git_tag.lstrip("v")
54
+
55
+ # 4. Compare
56
+ print("version in pyproject.toml: ", local_version)
57
+ print("version in git tag: ", git_version)
58
+ #print("version on pypi.org: ", pypi_version)
59
+ if Version(git_version) < Version(local_version):
60
+ git_tag_new = 'v' + local_version
61
+ print(f"Info: Updating git tag to '{git_tag_new}'")
62
+ subprocess.run(['git', 'tag', git_tag_new])
63
+ subprocess.run(['git', 'push', 'origin', git_tag_new]) # push new tag
64
+
65
+ success = run_tests()
66
+ if not success:
67
+ sys.exit()
68
+
69
+ success = build_package(require_new_version=True)
70
+ if not success:
71
+ sys.exit()
72
+
73
+ success = git_tag_and_push()
74
+ if not success:
75
+ sys.exit()
76
+
77
+ #subprocess.run(['twine', 'upload', 'dist/*'])
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "netlite"
7
- version = "1.0.0"
7
+ version = "1.0.2"
8
8
  authors = [
9
9
  { name="Hanno Homann", email="hanno.homann@example.com" },
10
10
  ]
@@ -18,9 +18,10 @@ class Layer(ABC):
18
18
  def print(self, Xin):
19
19
  '''Print layer properties.'''
20
20
  Xout = self.forward(Xin)
21
- print(f'- {self.__class__.__name__}:')
22
- print(f' - in =(:, {', '.join(str(s) for s in Xin.shape[1:])})')
23
- print(f' - out=(:, {', '.join(str(s) for s in Xout.shape[1:])})')
21
+ print(f"- {self.__class__.__name__}:")
22
+ print(f" - in =(:, {', '.join(str(s) for s in Xin.shape[1:])})")
23
+ print(f" - out=(:, {', '.join(str(s) for s in Xout.shape[1:])})")
24
+
24
25
  return Xout
25
26
 
26
27
  def get_weights(self):
@@ -109,7 +110,7 @@ class ConvolutionalLayer(Layer):
109
110
 
110
111
  output = np.tile(self.bias, (n, h_out, w_out, 1))
111
112
  weights = self.weights.reshape(-1, self.out_channels)
112
- self.conv(X, weights, output, h_out, w_out, n, k)
113
+ ConvolutionalLayer.conv(X, weights, output, h_out, w_out, n, k)
113
114
 
114
115
  return output
115
116
 
@@ -136,7 +137,7 @@ class ConvolutionalLayer(Layer):
136
137
  grad_backward_pad = np.pad(grad_backward, ((0, 0), (pad, pad), (pad, pad), (0, 0)), 'constant')
137
138
  rotated_weight = self.weights[::-1, ::-1, :, :].transpose(0, 1, 3, 2).reshape(-1, self.in_channels)
138
139
  grad_input = np.zeros((n, h_in, w_in, self.in_channels), dtype='f')
139
- self.conv(grad_backward_pad, rotated_weight, grad_input, h_in, w_in, n, k)
140
+ ConvolutionalLayer.conv(grad_backward_pad, rotated_weight, grad_input, h_in, w_in, n, k)
140
141
  return grad_input
141
142
 
142
143
  def get_weights(self):
@@ -1,3 +0,0 @@
1
- rm -rf dist
2
- python -m build
3
-
@@ -1 +0,0 @@
1
- pytest tests/ -v
@@ -1 +0,0 @@
1
- twine upload dist/*
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes