A PyTorch implementation of a Convolutional Neural Network for CIFAR-10 image classification, designed for deep learning capability assessment.
This project implements a CNN model that achieves >70% accuracy on the CIFAR-10 dataset, demonstrating proficiency in:
- Deep learning model architecture design
- PyTorch framework usage
- Training pipeline implementation
- Best practices in ML engineering
cifar10-cnn-project/
β
βββ cifar10_cnn.py # Main implementation file
βββ plot_results.py # Visualization script
βββ analyze_results.py # Analysis script
βββ README.md # This file
βββ requirements.txt # Python dependencies
β
βββ data/ # Dataset directory (auto-created)
β βββ cifar-10-batches-py/
β βββ data_batch_1
β βββ data_batch_2
β βββ data_batch_3
β βββ data_batch_4
β βββ data_batch_5
β βββ test_batch
β βββ batches.meta
β
βββ results/ # Training results (auto-generated)
βββ training_results.json # Complete metrics in JSON format
βββ training_summary.txt # Formatted training report
βββ training_history.csv # CSV for plotting/analysis
βββ model_architecture.txt # Model structure details
βββ best_model.pth # Best model checkpoint
βββ final_model.pth # Final model checkpoint
βββ plots/ # Visualizations (if plot_results.py run)
βββ accuracy_plot.png
βββ loss_plot.png
βββ learning_rate_plot.png
βββ epoch_time_plot.png
βββ training_dashboard.png
- Python 3.8+
- CUDA-capable GPU (optional, but recommended)
- Clone or download the project:
mkdir cifar10-cnn-project
cd cifar10-cnn-project
git clone <URL>- Create and activate virtual environment (recommended):
# On Linux/Mac
python3 -m venv venv
source venv/bin/activate
# On Windows
python -m venv venv
venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtpython cifar10_cnn.pyThe script will:
- Automatically download CIFAR-10 dataset (first run only)
- Initialize the CNN model
- Train for 20 epochs
- Display progress for each epoch
- Save the best model to
results/best_model.pth - Generate comprehensive results in
results/directory - Report final test accuracy
After training, the following files are automatically generated in the results/ directory:
Complete training metrics in JSON format:
{
"metadata": {
"start_time": "2024-01-15 14:30:00",
"device": "cuda",
"best_test_acc": 78.45,
"total_training_time_minutes": 12.5
},
"training_history": {
"epoch": [1, 2, 3, ...],
"train_loss": [1.523, 1.124, ...],
"train_acc": [44.21, 59.87, ...],
"test_acc": [52.34, 63.21, ...]
}
}Human-readable formatted report with:
- Training configuration
- Final results and best accuracy
- Epoch-by-epoch progress table
- Target achievement status
CSV file for easy plotting and analysis in Excel, Python, or R:
epoch,train_loss,train_acc,test_loss,test_acc,learning_rate,epoch_time
1,1.5234,44.21,1.2891,52.34,0.001,45.23
2,1.1245,59.87,1.0234,63.21,0.001,44.89Complete model structure and parameter count
Model checkpoints with state dictionaries
CIFAR10CNN(
Conv Block 1: [Conv2d(3β32) β BatchNorm β ReLU] Γ 2 β MaxPool
Conv Block 2: [Conv2d(32β64) β BatchNorm β ReLU] Γ 2 β MaxPool
Conv Block 3: [Conv2d(64β128) β BatchNorm β ReLU] Γ 2 β MaxPool
FC Layers: Flatten β Linear(2048β256) β ReLU β Dropout
β Linear(256β128) β ReLU β Dropout
β Linear(128β10)
)
Total Parameters: ~1.2M
| Metric | Value |
|---|---|
| Training Time (GPU) | ~10-15 minutes |
| Training Time (CPU) | ~45-60 minutes |
| Final Test Accuracy | 75-80% |
| Target Accuracy | β₯70% β |
Epoch [1/20] | Train Loss: 1.5234 | Train Acc: 44.21% | Test Loss: 1.2891 | Test Acc: 52.34% | Time: 45.23s
Epoch [2/20] | Train Loss: 1.1245 | Train Acc: 59.87% | Test Loss: 1.0234 | Test Acc: 63.21% | Time: 44.89s
...
Epoch [20/20] | Train Loss: 0.3421 | Train Acc: 88.12% | Test Loss: 0.6234 | Test Acc: 78.45% | Time: 45.01s
β SUCCESS: Final test accuracy β₯ 70%
Hyperparameters can be modified in the main() function:
num_epochs = 20 # Number of training epochs
batch_size = 128 # Batch size for training
learning_rate = 0.001 # Initial learning rate- Random cropping with padding
- Random horizontal flipping
- Normalization using dataset statistics
- Batch normalization for stable training
- Dropout for regularization
- Learning rate scheduling
- Model checkpointing (saves best model)
- Clean, modular architecture
- Comprehensive documentation
- Device-agnostic (CPU/GPU)
- Reproducible results (fixed random seed)
The script prints detailed metrics for each epoch:
- Train Loss & Accuracy: Performance on training set
- Test Loss & Accuracy: Performance on validation set
- Time per Epoch: Training speed
- Best Model: Automatically saved when test accuracy improves
# Reduce batch size in main()
batch_size = 64 # or 32- Use GPU if available
- Reduce
num_workersif CPU bottleneck - Decrease batch size
- Train for more epochs (e.g., 30-40)
- Adjust learning rate
- Increase model capacity
# Load best model
checkpoint = torch.load('results/best_model.pth')
model = CIFAR10CNN(num_classes=10)
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
print(f"Loaded model from epoch {checkpoint['epoch']}")
print(f"Test accuracy: {checkpoint['test_acc']:.2f}%")Simply open results/training_history.csv in Excel and create charts!
After training, check:
- training_summary.txt - Quick overview of results
- training_results.json - Detailed metrics for analysis
- training_history.csv - For plotting and visualization
The CNN model achieved a best test accuracy of 83.78% on the CIFAR-10 dataset after 20 epochs of training.
![]() Accuracy Over Epochs |
![]() Loss Over Epochs |
![]() Epoch Time (s) |
![]() Learning Rate Schedule |
![]() Overall Training Dashboard |
|
Candidate for: Master's Research Position
Research Area: Artificial Intelligence
Task: Deep Learning Capability
This project is created for academic evaluation purposes.
- CIFAR-10 dataset: Alex Krizhevsky, Vinod Nair, and Geoffrey Hinton
- PyTorch framework: Facebook AI Research
Note: This implementation follows best practices in deep learning and demonstrates proficiency in PyTorch, model architecture design, and training pipeline implementation.




