Repository navigation
Added CUDA support
π¦ 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 CUDASwitch back to CPU:
model.cuda(False) # Disable CUDAThe 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.0Optional: 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