Hierarchical Satellite Image Classification Using EfficientNet and Augmented Transformations

The primary goal was to perform satellite image classification using the EfficientNet model, leveraging the SuperGradients library for training, and applying extensive data augmentation techniques. The model’s performance was monitored through metrics and early stopping, and predictions were visualized to evaluate the model’s effectiveness.

Here’s a breakdown of everything I did

Importing Libraries: Imported essential libraries such as Pathlib, Sklearn, PIL, Torch, and SuperGradients for managing datasets, image transformations, model training, and evaluation.

Configuring Paths and Constants: Defined the configuration paths for training, validation, and test datasets. Set image processing parameters like input height, width, and normalization statistics based on ImageNet standards. Configured the device to use CUDA if available.

Splitting the Dataset: Loaded all image paths and split them into training, validation, and test sets using train_test_split while maintaining class stratification. Used the split_image_folder function to organize images into respective folders for training, validation, and testing.

Visualizing the Dataset: Visualized a sample of images from the training set along with their labels using examine_images. Plotted a bar chart showing the number of images in each subdirectory to ensure the dataset is well-balanced.

Data Augmentation: Defined a series of data augmentation transformations for the training dataset including resizing, cropping, horizontal and vertical flipping, rotation, and normalization. Applied the transformations and visualized an augmented image to verify the augmentation process.

Creating Data Loaders: Created data loaders for the training, validation, and test datasets using DataLoader from PyTorch. Loaded datasets using ImageFolder with the respective transformations applied.

Training the Model: Configured training parameters for the EfficientNet model, including early stopping based on accuracy and loss. Initialized the efficientnet_b0 model with pre-trained weights from ImageNet and set up the Trainer class from SuperGradients to manage the training process. Trained the model over multiple epochs, saving the best checkpoint based on validation performance.

Testing the Model: Loaded the best-performing model from the checkpoint and evaluated it on the test set using accuracy as a metric. Defined a function pred_and_plot_image to predict and plot images along with their predicted class and probability.

Visualizing Predictions: Plotted a series of random test images along with their predicted labels to visually inspect the model’s performance. Predicted a class label for an external image by loading it from a URL and visualizing the result.