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+
language:
|
| 3 |
+
- en
|
| 4 |
+
tags:
|
| 5 |
+
- image-classification
|
| 6 |
+
- aerial-imagery
|
| 7 |
+
- robotics
|
| 8 |
+
- computer-vision
|
| 9 |
+
datasets:
|
| 10 |
+
- aid_dataset
|
| 11 |
+
metrics:
|
| 12 |
+
- accuracy
|
| 13 |
+
- f1
|
| 14 |
+
model-index:
|
| 15 |
+
- name: Aerial Image Classification CNN
|
| 16 |
+
results:
|
| 17 |
+
- task:
|
| 18 |
+
type: image-classification
|
| 19 |
+
name: Image Classification
|
| 20 |
+
dataset:
|
| 21 |
+
name: AID (Aerial Image Dataset)
|
| 22 |
+
type: aid
|
| 23 |
+
metrics:
|
| 24 |
+
- type: accuracy
|
| 25 |
+
value: 0.9280
|
| 26 |
+
name: Test Accuracy
|
| 27 |
+
- type: f1
|
| 28 |
+
value: 0.93
|
| 29 |
+
name: Macro F1
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# Model Card for Aerial Image Classification (CNN & Classic ML)
|
| 33 |
+
|
| 34 |
+
## Model Details
|
| 35 |
+
|
| 36 |
+
### Model Description
|
| 37 |
+
This repository contains two types of models for classifying aerial images from the **AID dataset**:
|
| 38 |
+
1. **Convolutional Neural Network (CNN):** A lightweight ResNet-based model.
|
| 39 |
+
2. **Classic Machine Learning:** A Bag of Features (BoF) pipeline using SIFT descriptors and Softmax Regression.
|
| 40 |
+
|
| 41 |
+
These models were developed as part of a machine learning assignment to evaluate deep learning approaches against classical computer vision methods.
|
| 42 |
+
|
| 43 |
+
- **Model types:**
|
| 44 |
+
- CNN (PyTorch)
|
| 45 |
+
- BoF + Softmax (Scikit-learn/Joblib)
|
| 46 |
+
- **Language(s):** English
|
| 47 |
+
- **Resources:**
|
| 48 |
+
- CNN: ~1M parameters, ~16MB.
|
| 49 |
+
- Classic ML: ~100MB (includes vocabulary).
|
| 50 |
+
|
| 51 |
+
### Model Architecture
|
| 52 |
+
The architecture consists of an initial convolution layer followed by **three residual blocks**.
|
| 53 |
+
- **Residual Blocks:** Enable deeper feature extraction without degradation.
|
| 54 |
+
- **Layers:** Convolution, Batch Normalization, Max-Pooling.
|
| 55 |
+
- **Input:** $600 \times 600$ pixel images (resized as needed by the pipeline).
|
| 56 |
+
|
| 57 |
+
## Uses
|
| 58 |
+
|
| 59 |
+
### Direct Use
|
| 60 |
+
The model is intended for classifying high-resolution aerial scenes into one of 30 categories. It is suitable for:
|
| 61 |
+
- Autonomous UAV navigation and mapping.
|
| 62 |
+
- Environmental monitoring.
|
| 63 |
+
- Land use classification.
|
| 64 |
+
|
| 65 |
+
### Downstream Use
|
| 66 |
+
This model can be fine-tuned on other aerial or satellite imagery datasets.
|
| 67 |
+
|
| 68 |
+
## Training Data
|
| 69 |
+
|
| 70 |
+
The model was trained on the **Aerial Image Dataset (AID)**.
|
| 71 |
+
- **Source:** Google Earth imagery.
|
| 72 |
+
- **Size:** 10,000 images.
|
| 73 |
+
- **Classes:** 30 (e.g., Airport, Beach, Forest, Industrial, etc.).
|
| 74 |
+
- **Split:** 90% Training / 10% Test.
|
| 75 |
+
|
| 76 |
+
## Performance
|
| 77 |
+
|
| 78 |
+
The CNN significantly outperformed classical Machine Learning methods (SVM, Random Forest, etc.) evaluated on the same dataset.
|
| 79 |
+
|
| 80 |
+
| Metric | Value |
|
| 81 |
+
| :--- | :--- |
|
| 82 |
+
| **Test Accuracy** | **92.80%** |
|
| 83 |
+
| **Macro Average** | 0.93 |
|
| 84 |
+
| **Weighted Average** | 0.93 |
|
| 85 |
+
|
| 86 |
+
### Comparison with Classical Methods
|
| 87 |
+
| Model | Test Accuracy |
|
| 88 |
+
| :--- | :--- |
|
| 89 |
+
| **CNN (This Model)** | **0.9280** |
|
| 90 |
+
| SVM (RBF Kernel) | 0.7120 |
|
| 91 |
+
| Softmax Regression | 0.6580 |
|
| 92 |
+
| Random Forest | 0.5680 |
|
| 93 |
+
| Naïve Bayes | 0.5280 |
|
| 94 |
+
|
| 95 |
+
## Limitations
|
| 96 |
+
|
| 97 |
+
- **Data Bias:** The model is trained on Google Earth imagery (AID), so it may not generalize perfectly to aerial images with significantly different sensors, resolutions, or lighting conditions.
|
| 98 |
+
- **Scope:** Limited to the 30 classes defined in the AID dataset.
|
| 99 |
+
|
| 100 |
+
## How to Get Started
|
| 101 |
+
|
| 102 |
+
You can use the provided `demo.ipynb` notebook for a complete example. Below is a snippet to load both models.
|
| 103 |
+
|
| 104 |
+
### 1. Load Classic ML Model
|
| 105 |
+
```python
|
| 106 |
+
from huggingface_hub import hf_hub_download
|
| 107 |
+
import joblib
|
| 108 |
+
|
| 109 |
+
# Download model
|
| 110 |
+
model_path = hf_hub_download(
|
| 111 |
+
repo_id="JavideuS/aid-image-classification",
|
| 112 |
+
filename="classicML/models/bovw_softmax.pkl"
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Load pipeline
|
| 116 |
+
bundle = joblib.load(model_path)
|
| 117 |
+
pipeline = bundle['pipeline']
|
| 118 |
+
label_encoder = bundle['label_encoder']
|
| 119 |
+
|
| 120 |
+
# Predict
|
| 121 |
+
# pipeline.predict(["path/to/image.jpg"])
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
### 2. Load CNN Model
|
| 125 |
+
```python
|
| 126 |
+
import torch
|
| 127 |
+
from NeuralNets.model import PiattiCNN # Ensure you have the model definition
|
| 128 |
+
from huggingface_hub import hf_hub_download
|
| 129 |
+
|
| 130 |
+
# Download checkpoints
|
| 131 |
+
checkpoints_path = hf_hub_download(
|
| 132 |
+
repo_id="JavideuS/aid-image-classification",
|
| 133 |
+
filename="neuralNet/models/PiattiVL_v0.69.pth"
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
# Load model
|
| 137 |
+
checkpoints = torch.load(checkpoints_path, map_location='cpu')
|
| 138 |
+
model = PiattiCNN(num_classes=checkpoints['num_classes'])
|
| 139 |
+
model.load_state_dict(checkpoints['model_state_dict'])
|
| 140 |
+
model.eval()
|
| 141 |
+
|
| 142 |
+
# Inference
|
| 143 |
+
# ...
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
## Citation
|
| 147 |
+
|
| 148 |
+
If you use this model or the AID dataset, please cite the original dataset paper:
|
| 149 |
+
|
| 150 |
+
```bibtex
|
| 151 |
+
@article{aid_dataset,
|
| 152 |
+
title={AID: A Scene Classification Dataset},
|
| 153 |
+
author={Xia, Gui-Song and et al.},
|
| 154 |
+
journal={IEEE Transactions on Geoscience and Remote Sensing},
|
| 155 |
+
year={2017}
|
| 156 |
+
}
|
| 157 |
+
```
|