AeroVision CV
Computer vision for classifying weather scenes as Fog, Rain, or Snow.
AI Weather Classifier is an end-to-end computer-vision project that takes a weather photograph and predicts whether the scene is dominated by fog, rain, or snow.
The project combines a fine-tuned ResNet18 image classifier with a lightweight FastAPI inference service and a polished browser interface. The frontend is intentionally framework-free for easy deployment, while the model and API remain Python/PyTorch based.
The final model reached 93.29% validation accuracy on a reproducible held-out split of the labelled training set.
Metric note: 93.29% is validation accuracy. The separate external test folder contains unlabeled images, so the project does not claim an accuracy score for that test set.
- ResNet18 transfer learning with ImageNet initialization
- Three-class weather recognition: Fog / Rain / Snow
- Reproducible 80/20 validation split with seed
42 - Image augmentation during training
- GPU-aware PyTorch inference with CUDA when available
- FastAPI endpoint for real image inference
- Browser upload, drag-and-drop, preview, sample inputs, loading states, and errors
- No fake client-side predictions when the API is unavailable
- Confidence shown separately from measured model accuracy
- Static frontend is deployable independently from the heavyweight PyTorch backend
| Metric | Result |
|---|---|
| Validation accuracy | 93.29% |
| Validation samples | 417 |
| Correct predictions | 389 |
| Incorrect predictions | 28 |
| Input | 224 × 224 RGB |
| Classes | Fog / Rain / Snow |
| Backbone | ResNet18 |
| Validation split | 20% |
| Random seed | 42 |
| Class | Precision | Recall | F1 |
|---|---|---|---|
| Fog | 0.9333 | 0.9256 | 0.9295 |
| Rain | 0.9338 | 0.9137 | 0.9236 |
| Snow | 0.9317 | 0.9554 | 0.9434 |
| Macro average | 0.9329 | 0.9316 | 0.9322 |
Actual \ Predicted Fog Rain Snow
Fog 112 3 6
Rain 7 127 5
Snow 1 6 150
The full generated report is available at reports/evaluation_report.txt after evaluation.
┌─────────────────────────────┐
│ Browser UI │
│ Upload / Preview / Result │
└──────────────┬──────────────┘
│ multipart/form-data
▼
┌─────────────────────────────┐
│ FastAPI API │
│ POST /predict │
└──────────────┬──────────────┘
│
Resize + Normalize
│
▼
┌─────────────────────────────┐
│ ResNet18 │
│ Transfer Learned │
└──────────────┬──────────────┘
│
Softmax
│
▼
Fog / Rain / Snow
AI-Weather-Classifier/
├── backend/
│ └── main.py # FastAPI inference service
├── frontend/
│ ├── index.html # AeroVision CV interface
│ ├── script.js # Upload + API interaction
│ └── style.css # UI styling
├── models/
│ └── README.md # Checkpoint instructions
├── reports/
│ └── evaluation_report.txt # Validation metrics
├── data/ # Local dataset (ignored by Git)
├── train.py # Model training
├── evaluate.py # Validation evaluation
├── predict.py # Single-image / batch prediction
├── requirements.txt # Python dependencies
├── .gitignore
├── LICENSE
└── README.md
The training code expects the labelled dataset at:
data/
└── 3_3_train/
└── train/
├── fog/
├── rain/
└── snow/
The external unlabeled prediction set is expected at:
data/
└── 3_3_test_fin/
└── test/
├── 0.png
├── 1.png
└── ...
The raw dataset is intentionally excluded from Git because it is large and is not required to review the source code.
The trained checkpoint is intentionally not committed to the repository.
After training, the application expects:
models/weather_resnet18.pth
Generate it with:
python train.pyFor a hosted API, provide this checkpoint to the backend deployment using the host's persistent storage or artifact/model-storage mechanism.
git clone https://github.com/harshitdev-wq/AI-Weather-Classifier.git
cd AI-Weather-Classifierpython -m pip install -r requirements.txtFor NVIDIA GPU acceleration, install the PyTorch build appropriate for your CUDA environment.
Place the labelled images under:
data/3_3_train/train/fog/
data/3_3_train/train/rain/
data/3_3_train/train/snow/
python train.pyThe best validation checkpoint is written to:
models/weather_resnet18.pth
python evaluate.pyThis recreates the same validation split using seed 42 and writes:
reports/evaluation_report.txt
python predict.py "data/3_3_test_fin/test/0.png"python predict.pyThe generated CSV is written to:
reports/weather_predictions.csv
From the repository root:
python -m uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000API documentation:
http://127.0.0.1:8000/docs
Health endpoint:
http://127.0.0.1:8000/health
From the repository root, in a second terminal:
python -m http.server 5500Open:
http://127.0.0.1:5500/frontend/index.html
Returns service metadata, model status, supported classes, and validation accuracy.
Reports whether the model checkpoint is loaded successfully.
Accepts a multipart form upload using the field name file.
Supported image types:
image/jpeg
image/png
image/webp
Maximum request image size: 15 MB.
Example response:
{
"prediction": "rain",
"confidence": 99.96,
"probabilities": {
"fog": 0.01,
"rain": 99.96,
"snow": 0.03
},
"validation_accuracy": 93.29,
"device": "cuda"
}The API returns a per-image softmax confidence. That value describes the distribution produced by the network for the submitted image; it is not the same thing as validation accuracy and does not guarantee a correct prediction.
The UI therefore presents these as separate concepts.
The project is intentionally split into two deployable pieces because PyTorch and TorchVision are too large for a standard Vercel Python Function bundle.
Deploy the frontend/ directory as a static site.
Recommended Vercel configuration:
Root Directory: frontend
Framework Preset: Other
Build Command: none
Output Directory: .
Install Command: none
This prevents Vercel from trying to install the backend's heavyweight PyTorch dependencies.
Deploy backend/main.py on a service that supports Python and the required PyTorch runtime. The backend deployment must have access to:
models/weather_resnet18.pth
After the backend is deployed, set the frontend's API Config endpoint to the public /predict URL of that service.
ResNet18 is a compact convolutional architecture that provides a strong transfer-learning baseline for small-to-medium image classification tasks while remaining practical for local GPU inference.
The source repository is intended to remain lightweight, reviewable, and reproducible. Large image collections and binary model artifacts are therefore excluded from normal Git history.
A disconnected client should report an inference failure rather than fabricate a weather label. This keeps the demo trustworthy and makes production issues visible.
Vercel reports a huge Python bundle: confirm that the Vercel project root is set to frontend. The static frontend does not require the Python dependencies.
The API reports 503 Model checkpoint not found: place weather_resnet18.pth at models/weather_resnet18.pth in the backend environment.
The frontend says Local API Target: when running locally, start the FastAPI server on 127.0.0.1:8000 or use API Config to select another endpoint.
Predictions work locally but not online: the frontend and backend must be deployed separately unless the hosting platform supports the full PyTorch runtime and artifact size.
Released under the MIT License.
Built by Harshit as a practical deep-learning and deployment project.