Skip to content

abdubakr77/intel-image-classification-cnn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”οΈ Intel Image Classification β€” Transfer Learning with InceptionV3

Classifying natural scenes into 6 categories using Transfer Learning on top of a pre-trained InceptionV3 architecture.


πŸ“Œ Table of Contents


🧠 Overview

This project tackles a multi-class image classification problem using the Intel Image Classification dataset. Rather than training a CNN from scratch β€” which would require far more data and time β€” I chose to leverage Transfer Learning with InceptionV3 pretrained on ImageNet.

The motivation was simple: the dataset (~24K images) is decent but not massive. InceptionV3 brings powerful, battle-tested feature extraction that allows the model to generalize well even with limited fine-tuning.


πŸ“‚ Dataset

The dataset contains approximately 24,335 images across 3 splits:

Split Structure Purpose
seg_train Organized by class subfolders Training
seg_test Organized by class subfolders Validation during training
seg_pred Mixed images (no subfolders) Final real-world prediction

🏷️ Classes (6 Categories)

0 β†’ buildings
1 β†’ forest
2 β†’ glacier
3 β†’ mountain
4 β†’ sea
5 β†’ street

Note: The seg_pred folder contains mixed, unlabeled images β€” simulating a real deployment scenario where we don't know the ground truth.


πŸ“ Project Structure

πŸ“¦ Intel-Image-Classification/
β”œβ”€β”€ πŸ““ intel_image_classification.ipynb   ← Main notebook
β”œβ”€β”€ πŸ“„ README.md
└── πŸ“‚ Data/
    β”œβ”€β”€ seg_train/
    β”‚   β”œβ”€β”€ buildings/
    β”‚   β”œβ”€β”€ forest/
    β”‚   β”œβ”€β”€ glacier/
    β”‚   β”œβ”€β”€ mountain/
    β”‚   β”œβ”€β”€ sea/
    β”‚   └── street/
    β”œβ”€β”€ seg_test/
    β”‚   └── (same structure as seg_train)
    └── seg_pred/
        └── (flat folder β€” mixed images)

πŸ—οΈ Model Architecture

The model is built with Keras / TensorFlow using a clean Sequential pipeline:

Input (299Γ—299Γ—3)
       ↓
InceptionV3 (pretrained on ImageNet, frozen)
       ↓
GlobalAveragePooling2D  ← built into InceptionV3 via pooling="avg"
       ↓
Dense(6, activation="softmax")
       ↓
Output: probability distribution over 6 classes

πŸ”’ Why freeze InceptionV3?

I kept model.layers[0].trainable = False intentionally. Since the dataset is not huge, unfreezing InceptionV3 at this stage would risk catastrophic forgetting β€” where the pretrained weights get overwritten with noise. The frozen base acts as a powerful fixed feature extractor, while only the classification head is trained from scratch.

In a future iteration, fine-tuning (gradually unfreezing the last N layers) can squeeze out extra performance.


βš™οΈ Training Strategy

Data Preprocessing

ImageDataGenerator(preprocessing_function=preprocess_input)

Used InceptionV3's built-in preprocess_input (scales pixels to [-1, 1]) β€” the exact preprocessing the model was originally trained with. This is critical for Transfer Learning to work correctly.

I initially experimented with augmentation (zoom_range, shear_range, brightness_range, horizontal_flip), but found it wasn't necessary to achieve strong results with the frozen base. It remains commented out for easy re-enabling.

Key Hyperparameters

Parameter Value Reason
Image Size 299Γ—299 Required by InceptionV3
Batch Size (Train) 100 Balance between speed and stability
Batch Size (Validation) 16 Lighter memory footprint
Optimizer Adam Adaptive LR, works well out of the box
Loss categorical_crossentropy Multi-class classification standard
Epochs 10 (max) EarlyStopping handles the rest
Patience 3 Stop if val_loss doesn't improve for 3 epochs

Callbacks

EarlyStopping(monitor="val_loss", patience=3, restore_best_weights=True)

The restore_best_weights=True flag ensures we always keep the best checkpoint automatically β€” no manual saving needed.


πŸ“Š Results

Metric Train Validation
Accuracy ~94% ~92.5%
Loss ~0.15 ~0.20

πŸ“‰ Loss Curve

The training loss steadily decreased from ~0.42 β†’ ~0.15, while validation loss stabilized around 0.20. A small but consistent gap appeared after epoch 4.

πŸ“ˆ Accuracy Curve

Both curves climbed quickly in the first 2 epochs and plateaued β€” train at 94%, validation at 92.5%.

⚠️ Slight Overfitting Observed

There is a mild overfitting present:

  • The training accuracy kept improving after epoch 4, while validation accuracy plateaued.
  • The gap (~1.5%) is not alarming, but it's a signal.

The model is still generalizing well β€” 92.5% validation accuracy on a 6-class problem is solid. But this is something to address in future iterations.


πŸš€ Future Improvements

  • Add Dropout before the final Dense layer to reduce overfitting
  • Enable Data Augmentation (already scaffolded in the code, just uncomment)
  • Experiment with other architectures β€” EfficientNetV2, VGG, ConvNeXt
  • Use ReduceLROnPlateau callback alongside EarlyStopping
  • Use CheckPoint callback

πŸ› οΈ Technologies Used

Tool Purpose
Python 3 Core language
TensorFlow / Keras Model building & training
InceptionV3 Pretrained base model
NumPy Array operations
Pandas Prediction dataframe
Matplotlib Visualization

▢️ How to Run

  1. Clone the repo and set up your data:
Data/
β”œβ”€β”€ seg_train/
β”œβ”€β”€ seg_test/
└── seg_pred/
  1. Install dependencies:
pip install tensorflow numpy pandas matplotlib
  1. Run the notebook:
jupyter notebook intel_image_classification.ipynb

πŸ“¬ Notes

  • The seg_pred folder is handled differently from train/test β€” it uses flow_from_dataframe instead of flow_from_directory since it has no class subfolders.
  • Labels are automatically inferred from the seg_train folder structure using os.listdir.
  • Predictions include a confidence score (the max softmax probability) displayed alongside each image.

Built as part of a deep learning portfolio project exploring Transfer Learning on real-world image data.

About

Multi-class image classification model trained on the Intel Image Classification dataset using CNN architectures. The project focuses on building, training, and evaluating a deep learning model for scene classification.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors