Upload damage classification model
Browse files
README.md
CHANGED
@@ -1,3 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# damage-classifier-multi-task
|
2 |
|
3 |
## Home Damage Classification Model
|
@@ -36,30 +51,61 @@ This model was trained to classify damage to household items, identifying both t
|
|
36 |
- Moderate Damage
|
37 |
- Severe Damage
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
### Usage
|
40 |
|
41 |
```python
|
42 |
-
from transformers import ViTFeatureExtractor
|
43 |
from PIL import Image
|
|
|
44 |
|
45 |
# Load model and feature extractor
|
46 |
-
model =
|
47 |
feature_extractor = ViTFeatureExtractor.from_pretrained("USER/REPO_NAME")
|
48 |
|
49 |
# Prepare image
|
50 |
image = Image.open("path/to/image.jpg").convert("RGB")
|
51 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
52 |
|
53 |
-
# Get
|
54 |
outputs = model(**inputs)
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
```
|
64 |
|
65 |
For a more complete example, see the inference script in the [GitHub repository](https://github.com/yourusername/home-damage-classifier).
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: mit
|
4 |
+
library_name: transformers
|
5 |
+
pipeline_tag: image-classification
|
6 |
+
tags:
|
7 |
+
- vision
|
8 |
+
- damage-detection
|
9 |
+
- classification
|
10 |
+
- vit
|
11 |
+
- household-items
|
12 |
+
datasets:
|
13 |
+
- custom
|
14 |
+
---
|
15 |
+
|
16 |
# damage-classifier-multi-task
|
17 |
|
18 |
## Home Damage Classification Model
|
|
|
51 |
- Moderate Damage
|
52 |
- Severe Damage
|
53 |
|
54 |
+
### Multi-Task Architecture
|
55 |
+
|
56 |
+
This model uses a multi-task learning approach with:
|
57 |
+
|
58 |
+
1. A shared Vision Transformer (ViT) backbone that extracts features from the input image
|
59 |
+
2. Separate classification heads for:
|
60 |
+
- Item category identification
|
61 |
+
- Damage type classification
|
62 |
+
- Damage severity assessment
|
63 |
+
|
64 |
+
This approach allows the model to share knowledge between related tasks while making separate predictions for each aspect.
|
65 |
+
|
66 |
+
#### Advantages of Multi-Task Learning
|
67 |
+
|
68 |
+
- Shares knowledge across related tasks
|
69 |
+
- Requires fewer examples per combination
|
70 |
+
- Can perform well even with missing combinations
|
71 |
+
- Independent predictions for each aspect
|
72 |
+
|
73 |
### Usage
|
74 |
|
75 |
```python
|
76 |
+
from transformers import ViTFeatureExtractor
|
77 |
from PIL import Image
|
78 |
+
import torch
|
79 |
|
80 |
# Load model and feature extractor
|
81 |
+
model = torch.load("pytorch_model.bin") # Or use your preferred loading method
|
82 |
feature_extractor = ViTFeatureExtractor.from_pretrained("USER/REPO_NAME")
|
83 |
|
84 |
# Prepare image
|
85 |
image = Image.open("path/to/image.jpg").convert("RGB")
|
86 |
inputs = feature_extractor(images=image, return_tensors="pt")
|
87 |
|
88 |
+
# Get predictions
|
89 |
outputs = model(**inputs)
|
90 |
+
|
91 |
+
# Process multi-task outputs
|
92 |
+
item_logits = outputs['item_logits']
|
93 |
+
damage_logits = outputs['damage_type_logits']
|
94 |
+
severity_logits = outputs['severity_logits']
|
95 |
+
|
96 |
+
# Get predicted classes
|
97 |
+
item_class = torch.argmax(item_logits, dim=1).item()
|
98 |
+
damage_class = torch.argmax(damage_logits, dim=1).item()
|
99 |
+
severity_class = torch.argmax(severity_logits, dim=1).item()
|
100 |
+
|
101 |
+
# Map to class names (replace with your class mappings)
|
102 |
+
item_categories = ["microwave", "wall", "window", "fence", "glass", "fishbowl"]
|
103 |
+
damage_types = ["scratch", "dent", "break", "burn", "water_damage"]
|
104 |
+
severity_levels = ["no_damage", "minor_damage", "moderate_damage", "severe_damage"]
|
105 |
+
|
106 |
+
print(f"Item: {item_categories[item_class]}")
|
107 |
+
print(f"Damage Type: {damage_types[damage_class]}")
|
108 |
+
print(f"Severity: {severity_levels[severity_class]}")
|
109 |
```
|
110 |
|
111 |
For a more complete example, see the inference script in the [GitHub repository](https://github.com/yourusername/home-damage-classifier).
|