Skip to main content

🧠 GDnet — Custom Neural Network Framework (NumPy/CuPy)

Welcome to GDnet — a self-built, NumPy and CuPy-powered deep learning framework. It was created as a learning journey into the internal workings of neural networks. GDnet supports both CPU and GPU training, and includes layers like Dense, Conv2D, MaxPool2D, Flatten, and more.

⚠️ Note: This is not meant to compete with PyTorch or TensorFlow — it's a ** Learning framework** for learning, experimentation, and understanding how things work under the hood & not the best for production 😭. logo


✨ Features

  • ✅ Fully object-oriented design
  • ✅ CuPy (GPU) support with NumPy fallback
  • ✅ Custom activation functions (ReLU, Sigmoid, Softmax, etc.)
  • ✅ Built-in loss functions (CrossEntropy, MSE)
  • ✅ Layer types: Dense, Conv2D, MaxPool2D, Flatten, Dropout, Embedding,DebugLayer
  • ✅ Transformer layers: FeedForward, TransformerBlock
  • ✅ Debug logger with file-based logging
  • ✅ Early stopping, warmup epochs, L2/L1 regularization
  • ✅ Custom TextManager for text preprocessing and vectorization
  • ✅ Training with progress tracking and confusion matrix reporting
  • ✅ Built-in model save/load system with GPU-safe pickling
  • ✅ install directly using pip install gdnet

📦 Installation

you can clone the repo folder in your project and import it like this:

from gdnet.layers import DenseLayer, Conv2DLayer, MaxPool2D, Flatten, Dropout
from gdnet.lossfunctions import CrossEntropy, MSE
from gdnet.core import Model
from gdnet.utils import TextManager
pip install gdnet

🔍 Sample Usage

from gdnet.core import Model,LayerConfig
from gdnet.layers import  Conv2DLayer, DenseLayer, Flatten
from gdnet.activations import RELU, Softmax
from gdnet.lossfunctions import CrossEntropy
from gdnet.utils import AugmentImage
from sklearn.datasets import fetch_openml
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder
import time
# === Load and preprocess MNIST ===
print("Loading MNIST dataset...")
mnist = fetch_openml('mnist_784', version=1, as_frame=False)
print("Successfully fetched DataSet")
X = mnist.data.astype(np.float32) / 255.0
X = X.reshape(-1, 1, 28, 28)
print(f"Input shape: {X.shape}")
y = mnist.target.astype(int)
encoder = OneHotEncoder(sparse_output=False)
y_onehot = encoder.fit_transform(y.reshape(-1, 1))
X_train, X_test, y_train, y_test = train_test_split(X, y_onehot, test_size=0.1, random_state=42)
del mnist, X, y, y_onehot
Augmentor =  AugmentImage(rotate="random", shift="random",zoom="random")
X_train = Augmentor.augment_library(X_train)
layer_defs = [
     LayerConfig( Conv2DLayer,  RELU(), input_shape=(1, 28, 28), num_filters=8, filter_size=5, stride=2, padding=2),
     LayerConfig( Conv2DLayer,  RELU(), num_filters=16, filter_size=3, stride=2, padding=1),
     LayerConfig( Flatten, activation=None),
     LayerConfig( DenseLayer,  RELU(), output_size=64),
     LayerConfig( DenseLayer,  Softmax(), output_size=10)
]
model =  Model(layer_defs, input_size=(1, 28, 28), regularization='l2')
print("Starting Training")
try:
    model.train(
        X_train=X_train,
        y_train=y_train,
        X_test=X_test,
        y_test=y_test,
        learning_rate=0.01,
        epochs=100, 
        batch_size=128,
        verbose=True,
        loss_fn= CrossEntropy(),
        early_stopping=True,
        lambda_=0.0001, 
        patience=5,
        warmup_epochs=2
    )
    print("\nSaving model...")
    model.save("mnist-gdnet-conv.pkl")
except Exception as e:
    print(f"Training failed: {e}")

Results of the training

Example Results: * MNIST

🧐 Learn How Neural Networks Work

This project would not have been possible without these two incredible resources that explain complex concepts clearly:

If you’re trying to build something like this, start there! I did 🥹.


📁 Structure


Component Description
core.py Core model logic and training loop
layers/ All neural network layers
activations/ All activation functions
lossfunctions/ All loss functions
utils/ All utility functions
optimizers/ All optimizers
transformers/ All transformers
gpu.py GPU-Helper

🚪 Requirements

  • Python 3.11+
  • numpy, scikit-learn, nltk
  • Optional (for GPU): cupy, numba, torch (minimal fallback use)

❤️ Contributing

Feel free to fork, tweak, or use this as a base for your own learning journey. PRs that improve performance, readability, or structure are welcome! Hoping to push this to the next level, I'll be adding more layers and optimizers soon. and I'll be adding more examples soon. good luck! 😊 Have fun learning!

Metadata

Release files for gdnet 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gdnet 0.2
File Size Uploaded Provenance Actions
gdnet-0.2.tar.gz 25.1 kB Without provenance Details for gdnet-0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gdnet 0.2
File Interpreter ABI Platform Actions
gdnet-0.2-py3-none-any.whl Python 3 none any Details for gdnet-0.2-py3-none-any.whl

Total release size: 59.0 kB

Release files / gdnet-0.2.tar.gz

Download URL gdnet-0.2.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
775694e43b671a236a3f616aa54314d5170da92d25c522d182b726ab11485cec
BLAKE2b-256 checksum
How to use checksums
c104b4d6570c32efdf30a174163e4799c1f1064f869090b2245b6dd153d83038
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / gdnet-0.2-py3-none-any.whl

Download URL gdnet-0.2-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70d53c8eb0947a159ec01f9e14f57385d800bf639519daed295ac77856aec695
BLAKE2b-256 checksum
How to use checksums
62aa71436e11e165cf0320dcf4855a746babc07c790e50bb2b0f03d1c8abcdbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for gdnet 0.2

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.

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page