Downloads · 30 days
0
Divyanshu-Kumar19/aapdasetu-damage-assessment
aapdasetu-damage-assessment is a image classification model from Divyanshu-Kumar19. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
Post-disaster building damage classifier for the AapdaSetu platform. Given a photo of a disaster-affected building, the model classifies damage severity into one of three grades and drives automated compensation asses…
Downloads · 30 days
0
Access
Public
Updated Aug 20, 2026
Repo size
366 MB
Likes
0
Public
Click a slice to open those files.
.pt271 MB · 74%
From the Hugging Face model README
Post-disaster building damage classifier for the AapdaSetu platform. Given a photo of a disaster-affected building, the model classifies damage severity into one of three grades and drives automated compensation assessment in the AapdaSetu relief pipeline.
Part of the AapdaSetu project (Smart India Hackathon).
The full assessment service (this model + EXIF authenticity checks + pHash duplicate detection + compensation estimation) is deployed and publicly accessible:
🌐 https://aapdasetu-damage-api.onrender.com
/ · Swagger API docs: /docs · Health check: /healthPOST /api/assess-damage (multipart: photo, claimed_lat, claimed_lng, property_type, disaster_cutoff)best.onnx from this repo (torch-free, fits Render's 512 MB free tier). Free-tier instances sleep after ~15 min idle, so the first request after a pause cold-starts in a few seconds.| Architecture | ResNet50 (ImageNet-1K V2 pretrained backbone) + custom FC head (Dropout → Linear(2048, 3)) |
| Input | 224×224 RGB image |
| Preprocessing | Resize(256) → CenterCrop(224) → ToTensor → Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) |
| Classes | MINOR, MAJOR, DESTROYED (alphabetical ImageFolder order: DESTROYED=0, MAJOR=1, MINOR=2 — see class_mapping.json) |
| Checkpoint | best.pt (~271 MB, PyTorch dict — keys: model_state, class_to_idx, classes, epoch, val_acc, val_loss, optim_state) |
| ONNX export | best.onnx (~94 MB, opset 17, softmax baked in, input image, output scores, dynamic batch) — parity with PyTorch verified (max abs diff ≈ 6e-8) |
leak_check.json). Dataset hosted at Divyanshu-Kumar19/aapdasetu-damage-dataset.Held-out test set (244 images), with TTA:
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| DESTROYED | 0.990 | 0.981 | 0.986 | 104 |
| MAJOR | 0.982 | 1.000 | 0.991 | 54 |
| MINOR | 0.977 | 0.977 | 0.977 | 86 |
| Overall accuracy | 98.36% |
Full metrics: eval_report.json · Confusion matrix: confusion_matrix.png · ROC curves: roc_curves.png · Training curves: training_curves.png · Misclassified samples: misclassified.png · Training history: history.json · Split leak audit: leak_check.json
import json
import onnxruntime as ort
import numpy as np
from PIL import Image
from torchvision import transforms
mapping = json.load(open("class_mapping.json")) # {"DESTROYED": 0, "MAJOR": 1, "MINOR": 2}
idx_to_class = {int(v): k for k, v in mapping.items()}
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
img = Image.open("building.jpg").convert("RGB")
x = transform(img).unsqueeze(0).numpy()
sess = ort.InferenceSession("best.onnx", providers=["CPUExecutionProvider"])
probs = sess.run(["scores"], {"image": x})[0][0] # softmax already baked in
print("Damage grade:", idx_to_class[int(probs.argmax())])
print("All scores:", {idx_to_class[i]: round(float(p), 4) for i, p in enumerate(probs)})
best.pt)import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 1. Build the exact architecture used during training
model = models.resnet50(weights=None)
model.fc = nn.Sequential(
nn.Dropout(p=0.0), # training-only; inert at inference
nn.Linear(model.fc.in_features, 3),
)
# 2. Load the checkpoint
ckpt = torch.load("best.pt", map_location=device, weights_only=True)
model.load_state_dict(ckpt["model_state"])
model.to(device).eval()
# 3. IMPORTANT — use the checkpoint's index->class mapping.
# ImageFolder trained classes in ALPHABETICAL order
# (DESTROYED=0, MAJOR=1, MINOR=2), NOT ["MINOR", "MAJOR", "DESTROYED"].
idx_to_class = {int(v): k for k, v in ckpt["class_to_idx"].items()}
# 4. Preprocess exactly like training validation
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
# 5. Predict
img = Image.open("building.jpg").convert("RGB")
x = transform(img).unsqueeze(0).to(device)
with torch.no_grad():
probs = torch.softmax(model(x), dim=1)[0]
scores = {idx_to_class[i]: round(float(p), 4) for i, p in enumerate(probs)}
print("Damage grade:", idx_to_class[int(probs.argmax())])
print("All scores:", scores)
Download the checkpoints with:
hf download Divyanshu-Kumar19/aapdasetu-damage-assessment --local-dir ./model
| File | Description |
|---|---|
best.pt | Trained PyTorch checkpoint (state dict + metadata) |
best.onnx | ONNX export for CPU inference (softmax baked in) — used by the live deployment |
class_mapping.json | Class → index mapping (DESTROYED=0, MAJOR=1, MINOR=2) |
eval_report.json | Per-class precision / recall / F1 on the test set |
confusion_matrix.png | Confusion matrix visualization |
roc_curves.png | One-vs-rest ROC curves |
training_curves.png | Train/val loss & accuracy curves |
confidence_distribution.png | Prediction confidence distribution |
misclassified.png | Test samples the model got wrong |
history.json | Per-epoch training history |
leak_check.json | Train/val/test split leak audit |
MIT