A lightweight deep learning framework built from scratch using NumPy
Project description
Kronyx
A lightweight deep learning framework built from first principles using NumPy. Designed for education, research, and production use with a clean Keras-like API.
Features
| Feature | Description |
|---|---|
| Pure NumPy | No external ML dependencies, just NumPy |
| Clean API | Keras-like Sequential model interface |
| Educational | Built for learning with visualization and inspection tools |
| Layers | Dense, Conv2D, Flatten, Dropout, BatchNormalization |
| Activations | ReLU, Sigmoid, Tanh, Softmax |
| Optimizers | SGD, Adam with full state management |
| Callbacks | EarlyStopping, ModelCheckpoint, CSVLogger, ReduceLROnPlateau |
| Serialization | Save/load models with .krx format |
| Visualization | history.plot(), model.visualize(), model.summary() |
Installation
pip install kronyx
For development:
git clone https://github.com/Kronyx/kronyx.git
cd kronyx
pip install -e ".[dev]"
Quick Start
import numpy as np
from kronyx import Sequential, Dense, ReLU, Sigmoid, BinaryCrossEntropy, Adam, Accuracy
# XOR problem - binary classification
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y = np.array([[0], [1], [1], [0]])
model = Sequential()
model.add(Dense(2, 8)) # input_size=2, output_size=8
model.add(ReLU())
model.add(Dense(8, 1))
model.add(Sigmoid())
model.compile(
loss=BinaryCrossEntropy(),
optimizer=Adam(learning_rate=0.1),
metric=Accuracy()
)
model.fit(X, y, epochs=1000)
predictions = model.predict(X)
print(f"Accuracy: {(predictions.round() == y).mean():.2%}")
Binary Classification Example
import numpy as np
from kronyx import Sequential, Dense, ReLU, Sigmoid, BinaryCrossEntropy, Adam, Accuracy
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_train = np.array([[0], [1], [1], [0]])
model = Sequential()
model.add(Dense(2, 16))
model.add(ReLU())
model.add(Dense(16, 1))
model.add(Sigmoid())
model.compile(
loss=BinaryCrossEntropy(),
optimizer=Adam(learning_rate=0.1),
metric=Accuracy()
)
history = model.fit(X_train, y_train, epochs=500)
model.summary()
Multi-class Classification Example
import numpy as np
from kronyx import Sequential, Dense, ReLU, SoftmaxCategoricalCrossEntropy, Adam, Accuracy
# One-hot encoded labels
X = np.random.randn(100, 4)
y = np.eye(3)[np.random.randint(0, 3, 100)]
model = Sequential()
model.add(Dense(4, 32))
model.add(ReLU())
model.add(Dense(32, 3))
model.add(Softmax())
model.compile(
loss=SoftmaxCategoricalCrossEntropy(),
optimizer=Adam(learning_rate=0.01),
metric=Accuracy()
)
model.fit(X, y, epochs=100)
Convolutional Neural Network Example
import numpy as np
from kronyx import Sequential, Conv2D, ReLU, Flatten, Dense, Softmax
# Simple image input (batch, height, width, channels)
X = np.random.randn(10, 8, 8, 1)
y = np.eye(2)[np.random.randint(0, 2, 10)]
model = Sequential()
model.add(Conv2D(filters=8, kernel_size=3, padding='same'))
model.add(ReLU())
model.add(Flatten())
model.add(Dense(64, 2))
model.add(Softmax())
model.compile(
loss=SoftmaxCategoricalCrossEntropy(),
optimizer=Adam(learning_rate=0.01),
metric=Accuracy()
)
model.fit(X, y, epochs=10)
Saving and Loading Models
# Save complete model with architecture, weights, and configuration
model.save('model.krx')
# Load complete model
loaded = load_model('model.krx')
# Continue training or make predictions
loaded.predict(X_test)
Saving and Loading Weights
# Save only trainable weights
model.save_weights('weights.npz')
# Create a new model with matching architecture
new_model = Sequential()
new_model.add(Dense(2, 8))
new_model.add(ReLU())
new_model.add(Dense(8, 1))
new_model.add(Sigmoid())
# Load weights into the new model
new_model.load_weights('weights.npz')
Exporting JSON Architecture
# Export architecture to JSON string
json_str = model.to_json()
# Create model from JSON (weights initialized randomly)
model = Sequential.from_json(json_str)
.krx Archive Format
The .krx format is a zip archive containing:
model.krx
├── metadata.json # Framework version, Python/numpy versions, timestamp
├── architecture.json # Layer configuration, loss, optimizer settings
├── weights.npz # Trainable weights and biases (numpy archive)
└── optimizer.npz # Optional: optimizer state for resumable training
Examples
examples/xor.py- XOR problem with binary classificationexamples/iris_classification.py- Iris dataset multi-class classificationexamples/iris_dropout.py- Dropout regularization exampleexamples/iris_l2.py- L2 weight regularizationexamples/batchnorm_iris.py- Batch normalization demonstrationexamples/flatten_demo.py- Multi-dimensional input handlingexamples/conv2d_demo.py- Convolutional neural network exampleexamples/mnist_classifier.py- MNIST digit classification
Documentation
kronyx/
├── activations.py # ReLU, Sigmoid, Tanh, Softmax
├── layers.py # Dense, Conv2D, Flatten, Dropout, BatchNormalization
├── model.py # Sequential, History
├── optimizers.py # SGD, Adam
├── losses.py # BinaryCrossEntropy, CategoricalCrossEntropy
├── metrics.py # Accuracy
├── callbacks.py # Callback base, EarlyStopping, etc.
├── regularizers.py # L2
├── initializers.py # he_normal, xavier_uniform, lecun_normal
├── serialization.py # Save/load model (.krx format)
├── utils.py # Utility functions
└── exceptions.py # Error types
Contributing
See CONTRIBUTING.md for development guidelines.
Roadmap
See ROADMAP.md for planned features.
License
MIT License - see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kronyx-1.0.1.tar.gz.
File metadata
- Download URL: kronyx-1.0.1.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ae48c26a6a4100bf056d6e91611bc4455576e761e38ce6554476638c927ee36
|
|
| MD5 |
47b08b8d570800927c274c3d9741332f
|
|
| BLAKE2b-256 |
8ab84f780badb063de922a2f91ae72c2e8dc80b328a9011d43e284fe340e25e7
|
Provenance
The following attestation bundles were made for kronyx-1.0.1.tar.gz:
Publisher:
publish.yml on BillyMuthiani/Kronyx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kronyx-1.0.1.tar.gz -
Subject digest:
2ae48c26a6a4100bf056d6e91611bc4455576e761e38ce6554476638c927ee36 - Sigstore transparency entry: 2063537377
- Sigstore integration time:
-
Permalink:
BillyMuthiani/Kronyx@61e35731bdbdeefc8c35c4b27209c3f559c7c523 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/BillyMuthiani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@61e35731bdbdeefc8c35c4b27209c3f559c7c523 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kronyx-1.0.1-py3-none-any.whl.
File metadata
- Download URL: kronyx-1.0.1-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f444213c6eebef80e2093cf02eb8692b5dd9b6d3737d97d01a65caa8b6770dd7
|
|
| MD5 |
5265de2507676d92f6c7c9a30e4a261e
|
|
| BLAKE2b-256 |
6036c979581253b42eea23fa0c7cd4635d80a9a89fa20d155a9c17838ee4adea
|
Provenance
The following attestation bundles were made for kronyx-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on BillyMuthiani/Kronyx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kronyx-1.0.1-py3-none-any.whl -
Subject digest:
f444213c6eebef80e2093cf02eb8692b5dd9b6d3737d97d01a65caa8b6770dd7 - Sigstore transparency entry: 2063537393
- Sigstore integration time:
-
Permalink:
BillyMuthiani/Kronyx@61e35731bdbdeefc8c35c4b27209c3f559c7c523 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/BillyMuthiani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@61e35731bdbdeefc8c35c4b27209c3f559c7c523 -
Trigger Event:
release
-
Statement type: