CoolFace
Apppublic

Droid210/FleetVision

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
README.md245 linesDownload Raw Back to models
1# Models2 3This directory contains all machine learning models for Fleet-Vision autonomous vehicle inspection and dispatch system.4 5## Model A: Car Body Type Classifier6 7A ResNet-50 transfer learning model that classifies vehicle body types with 85.3% validation accuracy and 83% test accuracy.8 9### Architecture10 11- **Base Model**: ResNet-50 (pretrained on ImageNet)12- **Backbone**: Frozen (no gradient updates)13- **Custom Head**: 14  - Linear(2048 → 512)15  - ReLU + Dropout(0.3)16  - Linear(512 → 7)17- **Loss**: CrossEntropyLoss18- **Optimizer**: Adam (lr=0.001)19 20### Supported Classes21 221. Convertible232. Coupe243. Hatchback254. Pick-Up265. Sedan276. SUV287. VAN29 30### Dataset31 32```33data/model a/34├── train/          (5,350 images)35├── valid/          (1,397 images)36└── test/           (802 images)37```38 39### Performance40 41**Validation Set (1,397 images)**42- Accuracy: 85.33%43- Precision: 85.56%44- Recall: 85.33%45- F1-Score: 85.32%46 47**Test Set (802 images)**48- Accuracy: 83.04%49- Precision: 83.33%50- Recall: 83.04%51- F1-Score: 82.97%52 53**Per-Class F1 Scores (Validation)**54- Convertible: 0.9655- Coupe: 0.7256- Hatchback: 0.7557- Pick-Up: 0.8958- Sedan: 0.7659- SUV: 0.8260- VAN: 0.9761 62### Quick Start63 64#### Train65```bash66cd d:\Code\FleetThing67python models\model_a\main.py --epochs 10 --batch-size 3268```69 70#### Custom Parameters71```bash72python models\model_a\main.py \73  --epochs 20 \74  --batch-size 64 \75  --learning-rate 0.000576```77 78#### Inference79```python80from models.model_a.inference import classify_car_type81 82pred_class, confidence = classify_car_type(83    'path/to/car_image.jpg',84    model_path='weights/model a/best_body_classifier.pth'85)86print(f"Predicted: {pred_class}, Confidence: {confidence:.2%}")87```88 89### Module Structure90 91```92model_a/93├── __init__.py          # Package exports94├── config.py            # Constants & TrainConfig95├── data.py              # DataLoaders & transforms96├── model.py             # ResNet-50 architecture97├── train.py             # Training loop98├── evaluate.py          # Metrics & evaluation99├── inference.py         # Inference & model loading100├── utils.py             # Device & seed utilities101└── main.py              # CLI entry point102```103 104### Weights105 106Trained model checkpoint: `weights/model a/best_body_classifier.pth`107 108Contains:109- model_state_dict110- class_names111- best_val_acc112 113### Requirements114 115- PyTorch (CUDA-enabled)116- torchvision117- scikit-learn (for metrics)118- Pillow (for image loading)119 120Install: `pip install -r requirements.txt`121 122---123 124## Model B: Damage Assessment Classifier125 126A Swin-based binary damage detector that classifies a vehicle image as either `Whole` or `Damaged` and can also produce a Grad-CAM heatmap for damaged results.127 128### Architecture129 130- **Base Model**: `microsoft/swin-tiny-patch4-window7-224`131- **Backbone**: Frozen transformer backbone132- **Custom Head**: Hugging Face image classification head with 2 output labels133- **Loss**: CrossEntropyLoss134- **Optimizer**: AdamW135- **Training Focus**: Recall-oriented checkpoint selection to reduce missed damage cases136 137### Supported Classes138 1391. Whole1402. Damaged141 142### Dataset143 144The training pipeline supports two layouts:145 146```147data/model b/148├── train/149│   ├── Whole/150│   └── Damaged/151└── valid/152    ├── Whole/153    └── Damaged/154```155 156It can also read a `damage_assessment` layout with `samples.json` and a `data/` folder, plus optional `whole_pool/`, `Whole/`, or `train/Whole` / `valid/Whole` negatives.157 158### Performance159 160Model B is tuned primarily for damage detection recall, so the best checkpoint is saved when validation recall improves. This is intended to avoid false negatives where a damaged vehicle is incorrectly treated as safe.161 162### Quick Start163 164#### Train165```bash166cd d:\Code\FleetThing167python models\model_b\main.py --epochs 15 --batch-size 32 --recall-weight 2.0168```169 170#### Custom Parameters171```bash172python models\model_b\main.py \173  --epochs 20 \174  --batch-size 16 \175  --learning-rate 0.0001 \176  --recall-weight 2.0177```178 179#### Inference180```python181from models.model_b.inference import classify_damage182 183status, confidence = classify_damage(184    'path/to/car_image.jpg',185    model_path='weights/model b/best_damage_detector.pth'186)187print(f"Status: {status}, Confidence: {confidence:.2%}")188```189 190#### Heatmap Generation191```python192from models.model_b.grad_cam import generate_damage_heatmap193 194heatmap_path, heatmap = generate_damage_heatmap(195    image_path='path/to/car_image.jpg',196    model_path='weights/model b/best_damage_detector.pth',197)198print(heatmap_path)199```200 201### Module Structure202 203```204model_b/205├── __init__.py          # Package exports206├── config.py            # Constants & TrainConfig207├── data.py              # Datasets, splits, and transforms208├── model.py             # Swin image classifier209├── train.py             # Training loop210├── evaluate.py          # Metrics & evaluation211├── inference.py         # Inference & model loading212├── grad_cam.py          # Heatmap generation213├── inspection.py        # Multi-angle inspection helpers214└── main.py              # CLI entry point215```216 217### Weights218 219Trained model checkpoint: `weights/model b/best_damage_detector.pth`220 221Contains:222- `model_state_dict`223- `best_val_recall`224- `best_val_acc`225 226### Requirements227 228- PyTorch229- torchvision230- transformers231- scikit-learn (for metrics)232- Pillow (for image loading)233- OpenCV (for heatmap rendering)234 235Install: `pip install -r requirements.txt`236 237---238 239## Adding New Models240 2411. Create folder: `models/model_x/`2422. Add `__init__.py`, `config.py`, `data.py`, `model.py`, `train.py`, `evaluate.py`, `inference.py`, `main.py`2433. Follow Model A structure and patterns2444. Update this README with results and usage245