This project involves building and optimizing a Convolutional Neural Network (CNN) to classify images from the CIFAR-100 dataset into 100 fine-grained categories. The model leverages advanced deep learning techniques, such as SE (Squeeze-and-Excitation) blocks, Batch Normalization, and Data Augmentation, to enhance classification accuracy.
- Problem Statement
- Video Demo
- Dataset Overview
- Model Architecture
- Features and Techniques
- Results
- Setup and Usage
- Saved Model Integration
- Future Improvements
- Contributions
- License
The CIFAR-100 dataset comprises 32x32 color images across 100 categories, ranging from animals and plants to everyday objects. The goal of this project is to classify these images using a robust and optimized deep learning model.
Key objectives include:
- Designing a scalable CNN architecture.
- Using SE blocks for channel recalibration.
- Implementing data augmentation for better generalization.
- Achieving improved accuracy using batch normalization and dropout.
Screen.Recording.2024-12-18.at.2.14.18.PM.mov
- Training Samples: 50,000 images
- Test Samples: 10,000 images
- Image Dimensions: 32x32 pixels with 3 color channels (RGB)
- Classes: 100 distinct categories, such as 'apple', 'bicycle', 'lion', etc.
The dataset is publicly available and a standard benchmark for image classification tasks.
The CNN architecture designed for this project includes:
- Convolutional Layers: For feature extraction, with increasing complexity in subsequent layers.
- SE (Squeeze-and-Excitation) Blocks: To dynamically recalibrate channel importance.
- Batch Normalization: For faster convergence and stable training.
- Pooling Layers: MaxPooling layers to reduce spatial dimensions.
- Fully Connected Layers: Dense layers for classification.
- Dropout Layers: For regularization to prevent overfitting.
- Data Augmentation: Random transformations (flipping, rotation) applied to training data to enhance diversity.
- SE Blocks: A feature recalibration mechanism to improve learning of important features.
- Batch Normalization: Standardizes activations in intermediate layers for better training dynamics.
- Learning Rate Scheduling: An exponential decay schedule for optimal training convergence.
- Saved Model Format: The trained model is saved in
.keras
format for deployment readiness.
The final model achieved the following metrics on the CIFAR-100 dataset:
- Test Accuracy: ~66%
- Test Loss: ~1.64
Sample predictions are visualized, showcasing the model's confidence in the assigned class labels.
Ensure you have the following installed:
- Python 3.8+
- TensorFlow 2.0+
-
Clone the repository:
git clone https://github.com/obiwan04kanobi/CNN_CIFAR-100.git cd CNN_CIFAR-100
-
Test the saved model with an image:
from tensorflow.keras.models import load_model model = load_model('saved_models/cifar100_67_model.keras')
Save an image in the project directory and run:
from tensorflow.keras.preprocessing import image
img = image.load_img('your_image.png', target_size=(32, 32))
img_array = image.img_to_array(img) / 255.0
img_array = img_array[np.newaxis, ...]
prediction = model.predict(img_array)
print(f"Predicted class: {classes[np.argmax(prediction)]}")
The trained .keras
model can be easily integrated into:
- Django/Flask Web Applications: Use TensorFlow's APIs to load the model and serve predictions.
- Mobile Applications: Convert the model to TensorFlow Lite (
.tflite
) for efficient on-device inference. - Cloud Deployment: Deploy the model as a REST API using platforms like AWS, Azure, or GCP.
- Accuracy Optimization: Experiment with deeper networks or pre-trained models (transfer learning).
- Hyperparameter Tuning: Fine-tune learning rates, dropout rates, and layer configurations.
- Custom Loss Functions: Tailor loss functions to improve classification performance.
- Interactive Web Application: Build a live web app for real-time predictions.
This project is licensed under the MIT License. See the LICENSE
file for details.
- CIFAR-100 Dataset: Krizhevsky, 2009
- Squeeze-and-Excitation Networks: Hu et al., 2018
- TensorFlow and Keras community for providing tools to build and evaluate the model.