Computer vision for insurance claims assessment using YOLOv5 and ResNet with FastAPI and Streamlit
An intelligent claims assessment system using YOLOv5 for damage detection and ResNet for severity classification. The system automatically detects damage types, classifies severity levels, and provides cost estimates for insurance claims.
Key Metrics:
The system can detect and classify 10 types of damage:
| Damage Type | Description |
|---|---|
| scratch | Surface scratches on paint or metal |
| dent | Depressions in body panels |
| crack | Fractures in glass or body |
| rust | Oxidation and corrosion |
| broken_glass | Shattered windows or mirrors |
| water_damage | Water staining or flooding damage |
| fire_damage | Burn marks or smoke damage |
| structural | Frame or chassis damage |
| tire_damage | Tire punctures or blowouts |
| paint_damage | Chipped or peeled paint |
Each detected damage is classified into severity levels:
08-computer-vision-claims-assessment/
βββ config.yaml # Configuration for models & training
βββ requirements.txt # Python dependencies
βββ data/
β βββ generate_synthetic_data.py # Generate synthetic damage images
β βββ raw/ # Generated images & YOLO annotations
β βββ processed/ # Train/val/test splits
βββ src/
β βββ models/
β β βββ yolov5_detector.py # YOLOv5 damage detection
β β βββ resnet_classifier.py # ResNet severity classification
β β βββ train_detector.py # Training scripts
β β βββ predict.py # Inference pipeline
β βββ features/
β β βββ build_features.py # Data augmentation
β β βββ feature_config.py # Feature configuration
β βββ api/
β β βββ app.py # FastAPI endpoints
β β βββ schemas.py # Request/response schemas
β βββ dashboard/
β β βββ app.py # Streamlit dashboard
β βββ utils/
β β βββ data_loader.py # Custom datasets
β β βββ metrics.py # mAP, IoU, accuracy
β β βββ visualization.py # Bounding box visualization
β βββ visualization/
β βββ plots.py # Training curves, plots
βββ docker/
β βββ Dockerfile.api
β βββ Dockerfile.dashboard
β βββ docker-compose.yml
βββ scripts/
β βββ run_api.sh
β βββ run_dashboard.sh
β βββ train.py
βββ tests/
β βββ *.py # Unit tests
βββ models/ # Saved model weights
cd 08-computer-vision-claims-assessment
pip install -r requirements.txt
python data/generate_synthetic_data.py
This creates:
python scripts/train.py --model yolov5
Training details:
python scripts/train.py --model resnet
Training details:
bash scripts/run_api.sh
API available at http://localhost:8000
bash scripts/run_dashboard.sh
Dashboard available at http://localhost:8501
Via API:
curl -X POST "http://localhost:8000/predict" \
-F "image=@claim_image.jpg"
Via Python:
from src.models.predict import DamagePredictor
# Initialize predictor
predictor = DamagePredictor(
yolov5_path='models/yolov5/best_yolov5.pt',
resnet_path='models/resnet/best_resnet.pt'
)
# Predict
results = predictor.predict('claim_image.jpg')
# Results
for damage in results['damages']:
print(f"Type: {damage['type']}")
print(f"Severity: {damage['severity']}")
print(f"Confidence: {damage['confidence']:.2f}")
print(f"Estimated Cost: ${damage['cost_estimate']:,.0f}")
/predictUpload an image for damage assessment.
Request:
curl -X POST "http://localhost:8000/predict" \
-F "image=@image.jpg"
Response:
{
"success": true,
"image_id": "abc123",
"damages": [
{
"type": "dent",
"severity": "moderate",
"confidence": 0.92,
"bounding_box": [100, 150, 200, 250],
"cost_estimate": 300000
}
],
"total_cost_estimate": 300000,
"processing_time_ms": 150
}
/healthHealth check endpoint.
/model-infoReturns model information and metrics.
The Streamlit dashboard provides:
| Metric | Value |
|---|---|
| mAP@0.5 | 0.78 |
| Precision | 0.82 |
| Recall | 0.76 |
| F1-Score | 0.79 |
| Metric | Value |
|---|---|
| Accuracy | 0.86 |
| Precision | 0.84 |
| Recall | 0.83 |
| F1-Score | 0.83 |
Costs are estimated based on:
Example costs (CLP):
docker-compose up -d
Services:
http://localhost:8000http://localhost:8501| Component | Technology |
|---|---|
| Detection | YOLOv5s (Ultralytics) |
| Classification | ResNet-18 (PyTorch) |
| API | FastAPI + Uvicorn |
| Dashboard | Streamlit |
| Computer Vision | OpenCV, Pillow, Albumentations |
| Data | NumPy, Pandas |
pytest tests/ -v --cov=src
black src/
flake8 src/
MIT License - feel free to use for learning and development.
For questions or issues, please open a GitHub issue.