A deep learning project for classifying vehicle images into 5 categories using custom CNN architectures built with TensorFlow/Keras. Three model versions (v1, v2, v3) are trained and compared for performance.
This project builds and compares three custom Convolutional Neural Network (CNN) architectures to classify vehicle images. Each model is trained with data augmentation, early stopping, learning rate scheduling, and model checkpointing to ensure robust performance.
Classes:
- 🚗 Sedan
- 🚙 SUV
- 🛻 Pickup
- 🚘 Hatchback
- 🚌 Other
The dataset is organized into class-named folders:
Vehicle Type Image Dataset/
├── Seden/
├── SUV/
├── Pickup/
├── Hatchback/
└── Other/
Split ratio:
- Training: 70%
- Validation: 15%
- Test: 15%
Preprocessing:
- Input image size:
224 × 224 × 3 - Pixel normalization:
rescale = 1/255
Training Augmentation:
- Random rotation (±20°)
- Width & height shift (±20%)
- Horizontal flip
- Fill mode: nearest
A compact 3-block CNN suitable for fast training:
| Layer | Filters | Notes |
|---|---|---|
| Conv2D | 32 | ReLU |
| MaxPool2D | — | 2×2 |
| Conv2D | 64 | ReLU |
| MaxPool2D | — | 2×2 |
| Conv2D | 128 | ReLU |
| MaxPool2D | — | 2×2 |
| Dense | 128 | ReLU + Dropout(0.5) |
| Dense | 5 | Softmax |
Deeper architecture with batch normalization and progressive dropout for stronger regularization:
- 4 conv blocks (32 → 64 → 128 → 256 filters), each with dual Conv2D + BatchNorm + MaxPool + Dropout
- Fully connected head: 512 → 256 → 5 (Softmax)
Inspired by VGGNet with stacked conv layers and larger dense layers:
- 4 conv blocks (64 → 128 → 256 → 512 filters), each with 2–3 Conv2D layers + MaxPool
- Fully connected head: 1024 → 512 → 5 (Softmax)
All models share the same training setup:
| Parameter | Value |
|---|---|
| Optimizer | Adam (lr=0.001) |
| Loss | Categorical Crossentropy |
| Epochs | 50 (max) |
| Batch size | 32 |
| Early stopping | patience=10 |
| LR reduction | factor=0.5, patience=5, min=1e-7 |
| Checkpoint | Best val_accuracy saved |
├── Vehicle Type Image Dataset/
│ ├── Hatchback/
│ ├── Other/
│ ├── Pickup/
│ ├── SUV/
│ └── Seden/
├── vehicle_type.ipynb # Main notebook
├── v1_model_best.h5 # Saved best V1 model
├── v2_model_best.h5 # Saved best V2 model
├── v3_model_best.h5 # Saved best V3 model
├── v1_model_results.csv # V1 training history
├── v2_model_results.csv # V2 training history
├── v3_model_results.csv # V3 training history
├── confusion_matrix_v1_model.png
├── confusion_matrix_v2_model.png
├── confusion_matrix_v3_model.png
└── README.md
Python >= 3.8
tensorflow >= 2.x
numpy
pandas
matplotlib
seaborn
scikit-learn
Install all dependencies:
pip install tensorflow numpy pandas matplotlib seaborn scikit-learn- Clone the repository:
git clone https://github.com/Elsaraf1/vehicle-type-classification.git
cd vehicle-type-classification-
Place the dataset in the root directory following the folder structure above.
-
Run the notebook:
jupyter notebook vehicle_type.ipynb- Load a saved model for inference:
import tensorflow as tf
model = tf.keras.models.load_model('v1_model_best.h5')
# or v2_model_best.h5 / v3_model_best.h5
predictions = model.predict(your_image_batch)Training curves and confusion matrices are saved automatically during training:
| Model | Saved Weights | Training History | Confusion Matrix |
|---|---|---|---|
| V1 | v1_model_best.h5 |
v1_model_results.csv |
confusion_matrix_v1_model.png |
| V2 | v2_model_best.h5 |
v2_model_results.csv |
confusion_matrix_v2_model.png |
| V3 | v3_model_best.h5 |
v3_model_results.csv |
confusion_matrix_v3_model.png |
This project is licensed under the MIT License. See the LICENSE file for details.