SBANetwork
A CPU based lightweight neural network library inspired by keras.
Example of MNIST dataset
from sbanetwork.core.model import Model
Model Class
Model Class contains methods
INIT
model = Model([
Dense(128, activation="relu", name="dense_1"),
Dense(64, activation="relu", name="dense_2"),
Dense(10, activation="softmax", name="output")
])
Dense is inspired by Keras. It is used to create the layers. The first dense layer can automatically detect the input shape.
Dense(128, activation="relu"), #128 units in Neural Network
Here in Dense you can also use Regulizers which are also used to reduce the complexity and to reduce the overfitting.
There are given Regulizers -
1. l1
2. l2
3. maxnorm
Dropout is used to prevent the Overfitting into a model. Where you can drop the random nodes in every epoch so that it can identify the pattern instead of remembering.
Dropout(rate=0.3, name='dropout_1'), #rate(percentage), name(dropout name)
There are lots of activation functions are being used -
1. relu
2. leaky_relu
3. elu
4. selu
5. swish
6. mish
7. sigmoid
8. tanh
9. linear
10. softmax
11. gelu
12. bent_identity
13. gaussian
14. softplus
Compile
compile(optimizer='sgd', loss='mse', learning_rate=0.01, metrics=None)
There are lots of optimizers which are -
1. sgd
2. sgdmomentum
3. nag
4. adagrad
5. rmsprop
6. adam
The losses we are using are -
1. mse
2. mae
3. binary_crossentropy, bce
4. categorical_crossentropy, ce
5. huber
model.compile(
optimizer="adam",
loss="categorical_crossentropy",
learning_rate=0.001,
metrics=['accuracy']
)
Fit
Fit method is used to train the model with multiple parameters given in different environments.
fit(x_train, y_train, epochs=1, batch_size=32, validation_data=None, verbose=True, callbacks_list=None): It returns the training history.
The callbacks we are using -
1. early_stopping
2. model_checkpoints
3. learning_rate_scheduler
history = model.fit(
x_train, y_train_encoded,
epochs=10,
batch_size=32,
validation_data=(x_test, y_test_encoded),
verbose=True
)
Summary
model.summary()
Predict
predict(x, batch_size=32):
Export
model.export(path)
Load
model.load(path)
Pendings
1. To apply callbacks and Regulizers
2. Conv2d, flattening, Pooling etc
3. Validation Split
4. Preprocess
5. Experimental functions.
MNIST Dataset Example
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import OneHotEncoder
from sklearn.model_selection import train_test_split
from sbanetwork.core.model import Model
from sbanetwork.core.layers import Dense, Dropout
from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
x_train = x_train.reshape(-1, 784)
x_test = x_test.reshape(-1, 784)
encoder = OneHotEncoder(sparse_output=False)
y_train_encoded = encoder.fit_transform(y_train.reshape(-1, 1))
y_test_encoded = encoder.transform(y_test.reshape(-1, 1))
model = Model([
Dense(128, activation="relu", name="dense_1"),
Dense(64, activation="relu", name="dense_2"),
Dense(10, activation="softmax", name="output")
])
model.compile(
optimizer="adam",
loss="categorical_crossentropy",
learning_rate=0.001,
metrics=['accuracy']
)
history = model.fit(
x_train, y_train_encoded,
epochs=10,
batch_size=32,
validation_data=(x_test, y_test_encoded),
verbose=True
)
test_loss, test_metrics = model.evaluate(x_test, y_test_encoded)
for name, value in test_metrics.items():
print(f"{name.capitalize()}: {value * 100:.2f}%")
Metadata
Release files for sbanetwork 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sbanetwork-0.1.3.tar.gz | 22.1 kB | Without provenance | Details for sbanetwork-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sbanetwork-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for sbanetwork-0.1.3-py3-none-any.whl |
Total release size: 47.9 kB
Release files / sbanetwork-0.1.3.tar.gz
| Download URL | sbanetwork-0.1.3.tar.gz |
|---|---|
| Size | 22.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ab0395b7e77158534bac9464ec20b4d6b6c006b40821a8d27403c1ca68fd08c
|
|
BLAKE2b-256 checksum How to use checksums |
a3a5141854d8823616793842f7c53234eb601137c00835b2ab279b47412ba3d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Release files / sbanetwork-0.1.3-py3-none-any.whl
| Download URL | sbanetwork-0.1.3-py3-none-any.whl |
|---|---|
| Size | 25.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
289dd2f2bceb9e2d80df78279f1d0346e7c8de792990d5d72beff1fd018364a3
|
|
BLAKE2b-256 checksum How to use checksums |
46912f6b59b28898e340d2a1d3fa7f1882e0617ba40e7206e6cbf03b75bd0d88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Security for sbanetwork 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.