Skip to content

Added CUDA support

Choose a tag to compare

@77axel 77axel released this 30 Aug 23:28
· 125 commits to main since this release
1501e72

πŸ“¦ Release: v0.2.0 – Added support for CUDA

This update enhances PyCNN by adding CUDA (GPU) support, allowing accelerated training and inference when a compatible GPU and CuPy are available. Users can now toggle between CPU and GPU backends seamlessly.


πŸš€ Key Features

  • βœ… Fully functional CNN implementation from scratch
  • 🧠 Manual convolution, max pooling, and ReLU activations
  • πŸ” Forward and backward propagation with mini-batch gradient descent
  • 🏷 Multi-class classification via softmax and cross-entropy loss
  • πŸ’Ύ Model save/load using pickle
  • πŸ–Ό RGB image preprocessing with customizable filters
  • πŸ” Predict function to classify new unseen images
  • πŸ“Š Real-time training visualization (accuracy & loss per epoch)
  • ⚑ New: Optional CUDA acceleration for faster training and inference
  • πŸ”„ Automatic backend conversion when loading models trained on a different backend

πŸ–₯️ CUDA Usage

Enable CUDA (GPU) support:

from pycnn.model import CNN

model = CNN()
model.cuda(True)  # Enable CUDA

Switch back to CPU:

model.cuda(False)  # Disable CUDA

The model will automatically convert weights, biases, and datasets to the selected backend. Models trained on GPU can still be loaded on CPU and vice versa.


🏁 Training & Prediction

Training and prediction remain the same as previous versions. Example:

model.init(
    image_size=32,
    batch_size=32,
    h1=128,
    h2=64,
    learning_rate=0.01,
    epochs=10,
    dataset_path="data",
    max_image=200
)
model.load_dataset()
model.train_model(visualize=True)
model.save_model()

model.load_model("model.bin")
result = model.predict("path/to/image.png")
print("Prediction:", result)

🧾 Changelog

v0.2.0

  • New: CUDA backend support via CuPy
  • Automatic conversion between CPU and GPU backends
  • Models can be trained on one backend and loaded on another seamlessly
  • Minor improvements in training stability and performance

v0.1.1

  • Real-time training visualization with Matplotlib

v0.1.0

  • Initial version with full training and prediction pipeline

πŸ“Œ Installation

pip install git+https://github.com/77AXEL/PyCNN.git@v0.2.0

Optional: Install CuPy for CUDA support:

pip install cupy-cuda118  # Match your CUDA version

πŸ’¬ Feedback & Contributions

We welcome issues, suggestions, and contributions!
Check the Discussions tab or see CONTRIBUTING.md


πŸ›‘ Security

Found a security issue? Please report privately to:
πŸ“§ a.x.e.l777444000@gmail.com


πŸ“œ License

Released under the MIT License