kronyx 1.0.0__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.
- kronyx-1.0.0/LICENSE +21 -0
- kronyx-1.0.0/PKG-INFO +275 -0
- kronyx-1.0.0/README.md +235 -0
- kronyx-1.0.0/kronyx/__init__.py +68 -0
- kronyx-1.0.0/kronyx/activations.py +201 -0
- kronyx-1.0.0/kronyx/callbacks.py +445 -0
- kronyx-1.0.0/kronyx/exceptions.py +26 -0
- kronyx-1.0.0/kronyx/initializers.py +17 -0
- kronyx-1.0.0/kronyx/layers.py +540 -0
- kronyx-1.0.0/kronyx/losses.py +95 -0
- kronyx-1.0.0/kronyx/metrics.py +28 -0
- kronyx-1.0.0/kronyx/model.py +870 -0
- kronyx-1.0.0/kronyx/optimizers.py +232 -0
- kronyx-1.0.0/kronyx/regularizers.py +39 -0
- kronyx-1.0.0/kronyx/serialization.py +339 -0
- kronyx-1.0.0/kronyx/utils.py +18 -0
- kronyx-1.0.0/kronyx/version.py +2 -0
- kronyx-1.0.0/kronyx.egg-info/PKG-INFO +275 -0
- kronyx-1.0.0/kronyx.egg-info/SOURCES.txt +30 -0
- kronyx-1.0.0/kronyx.egg-info/dependency_links.txt +1 -0
- kronyx-1.0.0/kronyx.egg-info/requires.txt +13 -0
- kronyx-1.0.0/kronyx.egg-info/top_level.txt +1 -0
- kronyx-1.0.0/pyproject.toml +112 -0
- kronyx-1.0.0/setup.cfg +4 -0
- kronyx-1.0.0/tests/test_batchnorm.py +106 -0
- kronyx-1.0.0/tests/test_conv2d.py +77 -0
- kronyx-1.0.0/tests/test_dense.py +86 -0
- kronyx-1.0.0/tests/test_dropout.py +87 -0
- kronyx-1.0.0/tests/test_losses.py +87 -0
- kronyx-1.0.0/tests/test_optimizers.py +113 -0
- kronyx-1.0.0/tests/test_regularizers.py +49 -0
- kronyx-1.0.0/tests/test_serialization.py +191 -0
kronyx-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kronyx Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
kronyx-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kronyx
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight deep learning framework built from scratch using NumPy
|
|
5
|
+
Author: Kronyx Contributors
|
|
6
|
+
Maintainer: Kronyx Contributors
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/Kronyx/kronyx
|
|
9
|
+
Project-URL: Documentation, https://kronyx.github.io/kronyx
|
|
10
|
+
Project-URL: Repository, https://github.com/Kronyx/kronyx
|
|
11
|
+
Project-URL: Issues, https://github.com/Kronyx/kronyx/issues
|
|
12
|
+
Keywords: deep-learning,neural-network,numpy,machine-learning,framework,education
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Education
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
24
|
+
Classifier: Topic :: Education
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: numpy<3.0,>=1.26
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.3; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy>=1.11.2; extra == "dev"
|
|
35
|
+
Provides-Extra: plotting
|
|
36
|
+
Requires-Dist: matplotlib>=3.8; extra == "plotting"
|
|
37
|
+
Provides-Extra: dataframe
|
|
38
|
+
Requires-Dist: pandas>=2.2; extra == "dataframe"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# Kronyx
|
|
42
|
+
|
|
43
|
+
A lightweight deep learning framework built from first principles using NumPy. Designed for education, research, and production use with a clean Keras-like API.
|
|
44
|
+
|
|
45
|
+
[](https://pypi.org/project/kronyx/)
|
|
46
|
+
[](https://kronyx.github.io/kronyx)
|
|
47
|
+
[](https://www.python.org/downloads/)
|
|
48
|
+
[](https://opensource.org/licenses/MIT)
|
|
49
|
+
[](https://github.com/Kronyx/kronyx/actions/workflows/tests.yml)
|
|
50
|
+
[](https://docs.astral.sh/ruff/)
|
|
51
|
+
[](https://mypy-lang.org/)
|
|
52
|
+
|
|
53
|
+
## Features
|
|
54
|
+
|
|
55
|
+
| Feature | Description |
|
|
56
|
+
|---------|-------------|
|
|
57
|
+
| **Pure NumPy** | No external ML dependencies, just NumPy |
|
|
58
|
+
| **Clean API** | Keras-like Sequential model interface |
|
|
59
|
+
| **Educational** | Built for learning with visualization and inspection tools |
|
|
60
|
+
| **Layers** | Dense, Conv2D, Flatten, Dropout, BatchNormalization |
|
|
61
|
+
| **Activations** | ReLU, Sigmoid, Tanh, Softmax |
|
|
62
|
+
| **Optimizers** | SGD, Adam with full state management |
|
|
63
|
+
| **Callbacks** | EarlyStopping, ModelCheckpoint, CSVLogger, ReduceLROnPlateau |
|
|
64
|
+
| **Serialization** | Save/load models with .krx format |
|
|
65
|
+
| **Visualization** | `history.plot()`, `model.visualize()`, `model.summary()` |
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install kronyx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For development:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
git clone https://github.com/Kronyx/kronyx.git
|
|
77
|
+
cd kronyx
|
|
78
|
+
pip install -e ".[dev]"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Quick Start
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import numpy as np
|
|
85
|
+
from kronyx import Sequential, Dense, ReLU, Sigmoid, BinaryCrossEntropy, Adam, Accuracy
|
|
86
|
+
|
|
87
|
+
# XOR problem - binary classification
|
|
88
|
+
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
|
|
89
|
+
y = np.array([[0], [1], [1], [0]])
|
|
90
|
+
|
|
91
|
+
model = Sequential()
|
|
92
|
+
model.add(Dense(2, 8)) # input_size=2, output_size=8
|
|
93
|
+
model.add(ReLU())
|
|
94
|
+
model.add(Dense(8, 1))
|
|
95
|
+
model.add(Sigmoid())
|
|
96
|
+
|
|
97
|
+
model.compile(
|
|
98
|
+
loss=BinaryCrossEntropy(),
|
|
99
|
+
optimizer=Adam(learning_rate=0.1),
|
|
100
|
+
metric=Accuracy()
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
model.fit(X, y, epochs=1000)
|
|
104
|
+
predictions = model.predict(X)
|
|
105
|
+
print(f"Accuracy: {(predictions.round() == y).mean():.2%}")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Binary Classification Example
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import numpy as np
|
|
112
|
+
from kronyx import Sequential, Dense, ReLU, Sigmoid, BinaryCrossEntropy, Adam, Accuracy
|
|
113
|
+
|
|
114
|
+
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
|
|
115
|
+
y_train = np.array([[0], [1], [1], [0]])
|
|
116
|
+
|
|
117
|
+
model = Sequential()
|
|
118
|
+
model.add(Dense(2, 16))
|
|
119
|
+
model.add(ReLU())
|
|
120
|
+
model.add(Dense(16, 1))
|
|
121
|
+
model.add(Sigmoid())
|
|
122
|
+
|
|
123
|
+
model.compile(
|
|
124
|
+
loss=BinaryCrossEntropy(),
|
|
125
|
+
optimizer=Adam(learning_rate=0.1),
|
|
126
|
+
metric=Accuracy()
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
history = model.fit(X_train, y_train, epochs=500)
|
|
130
|
+
model.summary()
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Multi-class Classification Example
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import numpy as np
|
|
137
|
+
from kronyx import Sequential, Dense, ReLU, SoftmaxCategoricalCrossEntropy, Adam, Accuracy
|
|
138
|
+
|
|
139
|
+
# One-hot encoded labels
|
|
140
|
+
X = np.random.randn(100, 4)
|
|
141
|
+
y = np.eye(3)[np.random.randint(0, 3, 100)]
|
|
142
|
+
|
|
143
|
+
model = Sequential()
|
|
144
|
+
model.add(Dense(4, 32))
|
|
145
|
+
model.add(ReLU())
|
|
146
|
+
model.add(Dense(32, 3))
|
|
147
|
+
model.add(Softmax())
|
|
148
|
+
|
|
149
|
+
model.compile(
|
|
150
|
+
loss=SoftmaxCategoricalCrossEntropy(),
|
|
151
|
+
optimizer=Adam(learning_rate=0.01),
|
|
152
|
+
metric=Accuracy()
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
model.fit(X, y, epochs=100)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Convolutional Neural Network Example
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
import numpy as np
|
|
162
|
+
from kronyx import Sequential, Conv2D, ReLU, Flatten, Dense, Softmax
|
|
163
|
+
|
|
164
|
+
# Simple image input (batch, height, width, channels)
|
|
165
|
+
X = np.random.randn(10, 8, 8, 1)
|
|
166
|
+
y = np.eye(2)[np.random.randint(0, 2, 10)]
|
|
167
|
+
|
|
168
|
+
model = Sequential()
|
|
169
|
+
model.add(Conv2D(filters=8, kernel_size=3, padding='same'))
|
|
170
|
+
model.add(ReLU())
|
|
171
|
+
model.add(Flatten())
|
|
172
|
+
model.add(Dense(64, 2))
|
|
173
|
+
model.add(Softmax())
|
|
174
|
+
|
|
175
|
+
model.compile(
|
|
176
|
+
loss=SoftmaxCategoricalCrossEntropy(),
|
|
177
|
+
optimizer=Adam(learning_rate=0.01),
|
|
178
|
+
metric=Accuracy()
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
model.fit(X, y, epochs=10)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Saving and Loading Models
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
# Save complete model with architecture, weights, and configuration
|
|
188
|
+
model.save('model.krx')
|
|
189
|
+
|
|
190
|
+
# Load complete model
|
|
191
|
+
loaded = load_model('model.krx')
|
|
192
|
+
|
|
193
|
+
# Continue training or make predictions
|
|
194
|
+
loaded.predict(X_test)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Saving and Loading Weights
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
# Save only trainable weights
|
|
201
|
+
model.save_weights('weights.npz')
|
|
202
|
+
|
|
203
|
+
# Create a new model with matching architecture
|
|
204
|
+
new_model = Sequential()
|
|
205
|
+
new_model.add(Dense(2, 8))
|
|
206
|
+
new_model.add(ReLU())
|
|
207
|
+
new_model.add(Dense(8, 1))
|
|
208
|
+
new_model.add(Sigmoid())
|
|
209
|
+
|
|
210
|
+
# Load weights into the new model
|
|
211
|
+
new_model.load_weights('weights.npz')
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Exporting JSON Architecture
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
# Export architecture to JSON string
|
|
218
|
+
json_str = model.to_json()
|
|
219
|
+
|
|
220
|
+
# Create model from JSON (weights initialized randomly)
|
|
221
|
+
model = Sequential.from_json(json_str)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## .krx Archive Format
|
|
225
|
+
|
|
226
|
+
The `.krx` format is a zip archive containing:
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
model.krx
|
|
230
|
+
├── metadata.json # Framework version, Python/numpy versions, timestamp
|
|
231
|
+
├── architecture.json # Layer configuration, loss, optimizer settings
|
|
232
|
+
├── weights.npz # Trainable weights and biases (numpy archive)
|
|
233
|
+
└── optimizer.npz # Optional: optimizer state for resumable training
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Examples
|
|
237
|
+
|
|
238
|
+
- `examples/xor.py` - XOR problem with binary classification
|
|
239
|
+
- `examples/iris_classification.py` - Iris dataset multi-class classification
|
|
240
|
+
- `examples/iris_dropout.py` - Dropout regularization example
|
|
241
|
+
- `examples/iris_l2.py` - L2 weight regularization
|
|
242
|
+
- `examples/batchnorm_iris.py` - Batch normalization demonstration
|
|
243
|
+
- `examples/flatten_demo.py` - Multi-dimensional input handling
|
|
244
|
+
- `examples/conv2d_demo.py` - Convolutional neural network example
|
|
245
|
+
- `examples/mnist_classifier.py` - MNIST digit classification
|
|
246
|
+
|
|
247
|
+
## Documentation
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
kronyx/
|
|
251
|
+
├── activations.py # ReLU, Sigmoid, Tanh, Softmax
|
|
252
|
+
├── layers.py # Dense, Conv2D, Flatten, Dropout, BatchNormalization
|
|
253
|
+
├── model.py # Sequential, History
|
|
254
|
+
├── optimizers.py # SGD, Adam
|
|
255
|
+
├── losses.py # BinaryCrossEntropy, CategoricalCrossEntropy
|
|
256
|
+
├── metrics.py # Accuracy
|
|
257
|
+
├── callbacks.py # Callback base, EarlyStopping, etc.
|
|
258
|
+
├── regularizers.py # L2
|
|
259
|
+
├── initializers.py # he_normal, xavier_uniform, lecun_normal
|
|
260
|
+
├── serialization.py # Save/load model (.krx format)
|
|
261
|
+
├── utils.py # Utility functions
|
|
262
|
+
└── exceptions.py # Error types
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Contributing
|
|
266
|
+
|
|
267
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
|
|
268
|
+
|
|
269
|
+
## Roadmap
|
|
270
|
+
|
|
271
|
+
See [ROADMAP.md](ROADMAP.md) for planned features.
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT License - see [LICENSE](LICENSE)
|
kronyx-1.0.0/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# Kronyx
|
|
2
|
+
|
|
3
|
+
A lightweight deep learning framework built from first principles using NumPy. Designed for education, research, and production use with a clean Keras-like API.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/kronyx/)
|
|
6
|
+
[](https://kronyx.github.io/kronyx)
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://github.com/Kronyx/kronyx/actions/workflows/tests.yml)
|
|
10
|
+
[](https://docs.astral.sh/ruff/)
|
|
11
|
+
[](https://mypy-lang.org/)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
| Feature | Description |
|
|
16
|
+
|---------|-------------|
|
|
17
|
+
| **Pure NumPy** | No external ML dependencies, just NumPy |
|
|
18
|
+
| **Clean API** | Keras-like Sequential model interface |
|
|
19
|
+
| **Educational** | Built for learning with visualization and inspection tools |
|
|
20
|
+
| **Layers** | Dense, Conv2D, Flatten, Dropout, BatchNormalization |
|
|
21
|
+
| **Activations** | ReLU, Sigmoid, Tanh, Softmax |
|
|
22
|
+
| **Optimizers** | SGD, Adam with full state management |
|
|
23
|
+
| **Callbacks** | EarlyStopping, ModelCheckpoint, CSVLogger, ReduceLROnPlateau |
|
|
24
|
+
| **Serialization** | Save/load models with .krx format |
|
|
25
|
+
| **Visualization** | `history.plot()`, `model.visualize()`, `model.summary()` |
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install kronyx
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For development:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/Kronyx/kronyx.git
|
|
37
|
+
cd kronyx
|
|
38
|
+
pip install -e ".[dev]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
import numpy as np
|
|
45
|
+
from kronyx import Sequential, Dense, ReLU, Sigmoid, BinaryCrossEntropy, Adam, Accuracy
|
|
46
|
+
|
|
47
|
+
# XOR problem - binary classification
|
|
48
|
+
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
|
|
49
|
+
y = np.array([[0], [1], [1], [0]])
|
|
50
|
+
|
|
51
|
+
model = Sequential()
|
|
52
|
+
model.add(Dense(2, 8)) # input_size=2, output_size=8
|
|
53
|
+
model.add(ReLU())
|
|
54
|
+
model.add(Dense(8, 1))
|
|
55
|
+
model.add(Sigmoid())
|
|
56
|
+
|
|
57
|
+
model.compile(
|
|
58
|
+
loss=BinaryCrossEntropy(),
|
|
59
|
+
optimizer=Adam(learning_rate=0.1),
|
|
60
|
+
metric=Accuracy()
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
model.fit(X, y, epochs=1000)
|
|
64
|
+
predictions = model.predict(X)
|
|
65
|
+
print(f"Accuracy: {(predictions.round() == y).mean():.2%}")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Binary Classification Example
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import numpy as np
|
|
72
|
+
from kronyx import Sequential, Dense, ReLU, Sigmoid, BinaryCrossEntropy, Adam, Accuracy
|
|
73
|
+
|
|
74
|
+
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
|
|
75
|
+
y_train = np.array([[0], [1], [1], [0]])
|
|
76
|
+
|
|
77
|
+
model = Sequential()
|
|
78
|
+
model.add(Dense(2, 16))
|
|
79
|
+
model.add(ReLU())
|
|
80
|
+
model.add(Dense(16, 1))
|
|
81
|
+
model.add(Sigmoid())
|
|
82
|
+
|
|
83
|
+
model.compile(
|
|
84
|
+
loss=BinaryCrossEntropy(),
|
|
85
|
+
optimizer=Adam(learning_rate=0.1),
|
|
86
|
+
metric=Accuracy()
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
history = model.fit(X_train, y_train, epochs=500)
|
|
90
|
+
model.summary()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Multi-class Classification Example
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import numpy as np
|
|
97
|
+
from kronyx import Sequential, Dense, ReLU, SoftmaxCategoricalCrossEntropy, Adam, Accuracy
|
|
98
|
+
|
|
99
|
+
# One-hot encoded labels
|
|
100
|
+
X = np.random.randn(100, 4)
|
|
101
|
+
y = np.eye(3)[np.random.randint(0, 3, 100)]
|
|
102
|
+
|
|
103
|
+
model = Sequential()
|
|
104
|
+
model.add(Dense(4, 32))
|
|
105
|
+
model.add(ReLU())
|
|
106
|
+
model.add(Dense(32, 3))
|
|
107
|
+
model.add(Softmax())
|
|
108
|
+
|
|
109
|
+
model.compile(
|
|
110
|
+
loss=SoftmaxCategoricalCrossEntropy(),
|
|
111
|
+
optimizer=Adam(learning_rate=0.01),
|
|
112
|
+
metric=Accuracy()
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
model.fit(X, y, epochs=100)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Convolutional Neural Network Example
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import numpy as np
|
|
122
|
+
from kronyx import Sequential, Conv2D, ReLU, Flatten, Dense, Softmax
|
|
123
|
+
|
|
124
|
+
# Simple image input (batch, height, width, channels)
|
|
125
|
+
X = np.random.randn(10, 8, 8, 1)
|
|
126
|
+
y = np.eye(2)[np.random.randint(0, 2, 10)]
|
|
127
|
+
|
|
128
|
+
model = Sequential()
|
|
129
|
+
model.add(Conv2D(filters=8, kernel_size=3, padding='same'))
|
|
130
|
+
model.add(ReLU())
|
|
131
|
+
model.add(Flatten())
|
|
132
|
+
model.add(Dense(64, 2))
|
|
133
|
+
model.add(Softmax())
|
|
134
|
+
|
|
135
|
+
model.compile(
|
|
136
|
+
loss=SoftmaxCategoricalCrossEntropy(),
|
|
137
|
+
optimizer=Adam(learning_rate=0.01),
|
|
138
|
+
metric=Accuracy()
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
model.fit(X, y, epochs=10)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Saving and Loading Models
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
# Save complete model with architecture, weights, and configuration
|
|
148
|
+
model.save('model.krx')
|
|
149
|
+
|
|
150
|
+
# Load complete model
|
|
151
|
+
loaded = load_model('model.krx')
|
|
152
|
+
|
|
153
|
+
# Continue training or make predictions
|
|
154
|
+
loaded.predict(X_test)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Saving and Loading Weights
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
# Save only trainable weights
|
|
161
|
+
model.save_weights('weights.npz')
|
|
162
|
+
|
|
163
|
+
# Create a new model with matching architecture
|
|
164
|
+
new_model = Sequential()
|
|
165
|
+
new_model.add(Dense(2, 8))
|
|
166
|
+
new_model.add(ReLU())
|
|
167
|
+
new_model.add(Dense(8, 1))
|
|
168
|
+
new_model.add(Sigmoid())
|
|
169
|
+
|
|
170
|
+
# Load weights into the new model
|
|
171
|
+
new_model.load_weights('weights.npz')
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Exporting JSON Architecture
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
# Export architecture to JSON string
|
|
178
|
+
json_str = model.to_json()
|
|
179
|
+
|
|
180
|
+
# Create model from JSON (weights initialized randomly)
|
|
181
|
+
model = Sequential.from_json(json_str)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## .krx Archive Format
|
|
185
|
+
|
|
186
|
+
The `.krx` format is a zip archive containing:
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
model.krx
|
|
190
|
+
├── metadata.json # Framework version, Python/numpy versions, timestamp
|
|
191
|
+
├── architecture.json # Layer configuration, loss, optimizer settings
|
|
192
|
+
├── weights.npz # Trainable weights and biases (numpy archive)
|
|
193
|
+
└── optimizer.npz # Optional: optimizer state for resumable training
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Examples
|
|
197
|
+
|
|
198
|
+
- `examples/xor.py` - XOR problem with binary classification
|
|
199
|
+
- `examples/iris_classification.py` - Iris dataset multi-class classification
|
|
200
|
+
- `examples/iris_dropout.py` - Dropout regularization example
|
|
201
|
+
- `examples/iris_l2.py` - L2 weight regularization
|
|
202
|
+
- `examples/batchnorm_iris.py` - Batch normalization demonstration
|
|
203
|
+
- `examples/flatten_demo.py` - Multi-dimensional input handling
|
|
204
|
+
- `examples/conv2d_demo.py` - Convolutional neural network example
|
|
205
|
+
- `examples/mnist_classifier.py` - MNIST digit classification
|
|
206
|
+
|
|
207
|
+
## Documentation
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
kronyx/
|
|
211
|
+
├── activations.py # ReLU, Sigmoid, Tanh, Softmax
|
|
212
|
+
├── layers.py # Dense, Conv2D, Flatten, Dropout, BatchNormalization
|
|
213
|
+
├── model.py # Sequential, History
|
|
214
|
+
├── optimizers.py # SGD, Adam
|
|
215
|
+
├── losses.py # BinaryCrossEntropy, CategoricalCrossEntropy
|
|
216
|
+
├── metrics.py # Accuracy
|
|
217
|
+
├── callbacks.py # Callback base, EarlyStopping, etc.
|
|
218
|
+
├── regularizers.py # L2
|
|
219
|
+
├── initializers.py # he_normal, xavier_uniform, lecun_normal
|
|
220
|
+
├── serialization.py # Save/load model (.krx format)
|
|
221
|
+
├── utils.py # Utility functions
|
|
222
|
+
└── exceptions.py # Error types
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Contributing
|
|
226
|
+
|
|
227
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines.
|
|
228
|
+
|
|
229
|
+
## Roadmap
|
|
230
|
+
|
|
231
|
+
See [ROADMAP.md](ROADMAP.md) for planned features.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT License - see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from kronyx.activations import ReLU, Sigmoid, Softmax, Tanh
|
|
2
|
+
from kronyx.callbacks import (
|
|
3
|
+
Callback,
|
|
4
|
+
CSVLogger,
|
|
5
|
+
EarlyStopping,
|
|
6
|
+
ModelCheckpoint,
|
|
7
|
+
ReduceLROnPlateau,
|
|
8
|
+
)
|
|
9
|
+
from kronyx.exceptions import (
|
|
10
|
+
ConfigurationError,
|
|
11
|
+
NeuralnetError,
|
|
12
|
+
NotCompiledError,
|
|
13
|
+
OptimizerError,
|
|
14
|
+
ShapeError,
|
|
15
|
+
)
|
|
16
|
+
from kronyx.initializers import he_normal, lecun_normal, xavier_uniform
|
|
17
|
+
from kronyx.layers import BatchNormalization, Conv2D, Dense, Dropout, Flatten
|
|
18
|
+
from kronyx.losses import (
|
|
19
|
+
BinaryCrossEntropy,
|
|
20
|
+
CategoricalCrossEntropy,
|
|
21
|
+
SoftmaxCategoricalCrossEntropy,
|
|
22
|
+
)
|
|
23
|
+
from kronyx.metrics import Accuracy
|
|
24
|
+
from kronyx.model import History, Sequential
|
|
25
|
+
from kronyx.optimizers import SGD, Adam
|
|
26
|
+
from kronyx.regularizers import L2
|
|
27
|
+
from kronyx.serialization import SerializationError, from_json, load_model
|
|
28
|
+
from kronyx.utils import set_seed
|
|
29
|
+
from kronyx.version import __version__
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"Dense",
|
|
33
|
+
"Dropout",
|
|
34
|
+
"BatchNormalization",
|
|
35
|
+
"Flatten",
|
|
36
|
+
"Conv2D",
|
|
37
|
+
"ReLU",
|
|
38
|
+
"Sigmoid",
|
|
39
|
+
"Tanh",
|
|
40
|
+
"Softmax",
|
|
41
|
+
"BinaryCrossEntropy",
|
|
42
|
+
"SoftmaxCategoricalCrossEntropy",
|
|
43
|
+
"CategoricalCrossEntropy",
|
|
44
|
+
"SGD",
|
|
45
|
+
"Adam",
|
|
46
|
+
"Accuracy",
|
|
47
|
+
"Sequential",
|
|
48
|
+
"History",
|
|
49
|
+
"NeuralnetError",
|
|
50
|
+
"ConfigurationError",
|
|
51
|
+
"NotCompiledError",
|
|
52
|
+
"ShapeError",
|
|
53
|
+
"OptimizerError",
|
|
54
|
+
"he_normal",
|
|
55
|
+
"xavier_uniform",
|
|
56
|
+
"lecun_normal",
|
|
57
|
+
"Callback",
|
|
58
|
+
"EarlyStopping",
|
|
59
|
+
"ModelCheckpoint",
|
|
60
|
+
"CSVLogger",
|
|
61
|
+
"ReduceLROnPlateau",
|
|
62
|
+
"L2",
|
|
63
|
+
"set_seed",
|
|
64
|
+
"load_model",
|
|
65
|
+
"from_json",
|
|
66
|
+
"SerializationError",
|
|
67
|
+
"__version__",
|
|
68
|
+
]
|