Military Aircraft Classification preview

Military Aircraft Classification

Machine Learning | Multi-Class Classification

TECHNOLOGIES

Python
TensorFlow
Keras
NumPy

Overview

The goal of this project is to classify images of military aircraft into one of 80 distinct classes using deep learning. The system leverages state-of-the-art Convolutional Neural Network (CNN) architecturesβ€”including EfficientNetB3, ResNet50, MobileNetV2, InceptionV3, and InceptionResNetV2β€”to achieve high accuracy. Using transfer learning, these models are adapted from pre-trained ImageNet weights to the specific domain of military aircraft recognition. The project utilizes the "Military Aircraft Detection Dataset" from Kaggle, comprising over 33,000 images. The solution is implemented using TensorFlow and Keras, featuring a custom data pipeline and modular model definitions to support both frozen feature extraction and full fine-tuning.

πŸ“Š Best Model: Unfrozen EfficientNetB3 trained for 14 epochs

  • Training Accuracy: 98.5%
  • Training Loss: 0.14
  • Testing Accuracy: 95.5%
  • Testing Loss: 0.265

Architecture

The system follows a standard deep learning pipeline architecture:

  1. Data Ingestion & Preprocessing:
    • Raw images are loaded and resized to a standard 224x224 input size.
    • Images can be processed as RGB or Grayscale.
    • Model-specific preprocessing (e.g., normalization schemes for EfficientNet vs ResNet) is applied dynamically during data generation.
  2. Model Layer:
    • Base Network: A pre-trained CNN (e.g., EfficientNetB3) serves as the feature extractor.
    • Adaptation Head: A custom classification head is attached to the base:
      • BatchNormalization for stability.
      • Dense layer (256 units, ReLU activation, L2 regularization).
      • Dropout (0.2) for regularization.
      • Output Dense layer (80 units, Softmax activation).
  3. Training Loop:
    • Optimization using the Adamax optimizer.
    • Loss calculation using Categorical Cross-Entropy.
    • Metrics tracking for Accuracy and Loss.

Key Components

  • models.py: The core factory module containing definitions for all model architectures. It functions as a flexible builder that can instantiate models in either "frozen" (feature extraction only) or "trainable" (fine-tuning) modes. It includes definitions for:
    • customCNN: A baseline CNN built from scratch.
    • efficientNetB3_80, resnet50_80, mobilenetV2_80, etc.
  • dataGenerator.py (AircraftDataGenerator): A custom class inheriting from keras.utils.Sequence. It handles efficient, batched data loading from the disk, ensuring the system can train on large datasets without memory exhaustion. It manages shuffling, resizing, and on-the-fly preprocessing.
  • classification.py: The main driver script. It handles:
    • Dataset organization and cleaning (reformatDataset).
    • Orchestration of training and testing loops.
    • Saving and loading of model inference weights.
  • results.py: A dedicated module for visualizing training metrics. It contains hardcoded results from experiments to reproduce performance graphs (Accuracy/Loss vs Global Epochs) using Matplotlib.

Design Principles

  • Modularity: The architecture separates model definitions (models.py), data handling (dataGenerator.py), and execution logic (classification.py). This allows for easy swapping of base models (e.g., switching from ResNet to MobileNet requires changing just one function call) without rewriting the training loop.
  • Efficiency via Generators: Instead of pre-loading all 33k+ images into RAM, the AircraftDataGenerator streams batches on demand. This fits the "Load-Process-Train" pattern, essential for deep learning on consumer hardware.
  • Transfer Learning Strategy: The system is designed to leverage "Knowledge Transfer." By initializing with ImageNet weights, the models converge significantly faster and achieve higher accuracy than training from scratch, especially given the specific visual features of aircraft.
  • Experimentation-First: The code is structured to facilitate rapid comparison experiments (frozen vs. unfrozen, batch size impact, etc.), with a dedicated results module to visualize these comparisons clearly.

Dataset

Source: Military Aircraft Detection Dataset (Kaggle)

Classification Set:

  • Total images: 33,872
  • Classes: 80 types of military aircraft
  • Image sizes: Ranges from 5x10 px to 4912x7360 px
  • Preprocessing: All images resized to 224x224 for model compatibility
  • Split: 80% training, 20% testing

Object Detection Set:

  • Total images: 19,214
  • Annotations: CSV files with bounding box coordinates and class labels
  • Split: 75% training, 18% validation, 7% testing

πŸ“Š Results of unfrozen models trained for 5 epochs

ModelTrain AccTest AccBatch SizeNotes
EfficientNetB395%88%16Best performance
ResNet5080%72%16
MobileNetV283%65%16Fastest but lowest accuracy

Project Structure

military-aircraft-classification/
β”œβ”€β”€ images/                                            # Reformatted and structured dataset
β”‚   └── 33,872 .jpg images                             # Images
β”œβ”€β”€ savedModels/                                       # Saved model weights and architectures
β”‚   └── various saved models
β”œβ”€β”€ results/                                           # Accuracy/Loss plots
β”‚   β”œβ”€β”€ batchSize16_frozen_training_accuracy_loss.png
β”‚   β”œβ”€β”€ batchSize32_frozen_training_accuracy_loss.png
β”‚   └── batchSize_vs_frozen_test_accuracy_loss_.png
β”œβ”€β”€ labels.txt                                         # Class label mappings
β”œβ”€β”€ README.md                                          # Project overview and documentation
β”œβ”€β”€ classification.py                                  # Main script, contains training, evaluation, data generator, and architecture definitions
β”œβ”€β”€ results.py                                         # Results script, used to visualize the results
└── requirements.txt                                   # Python dependencies

Living, learning & leveling up one day at a time.

Handcrafted by me

Copyright Β© 2024