A convolutional neural network built with PyTorch to classify images from the CIFAR-10 dataset into 10 categories.
This project implements a CNN from scratch to classify 32x32 color images into one of 10 classes: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck.
- 3 convolutional blocks (Conv2d → ReLU → MaxPool2d), with channel depth increasing 3 → 32 → 64 → 128
- Flatten layer
- 2 fully connected layers (2048 → 256 → 10)
- CIFAR-10, loaded via
torchvision.datasets.CIFAR10 - Preprocessing: images converted to tensors and normalized to a [-1, 1] range
- Loss function: Cross-Entropy Loss
- Optimizer: Adam
- Epochs: 10
- Batch size: 64
- Final training loss: ~0.109
- Test accuracy: 74.59%
torch
torchvision
python train.pyThis trains the model and saves the weights to cifar10_cnn.pth.
To load the saved model for inference:
model = CNN()
model.load_state_dict(torch.load("cifar10_cnn.pth"))
model.eval()Training loss is noticeably lower than test accuracy would suggest, indicating some overfitting. Potential improvements include dropout, data augmentation, and batch normalization.
Samir B K GitHub: github.com/Samir-BK