Update README.md
Browse files
README.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
```py
|
5 |
Classification Report:
|
6 |
precision recall f1-score support
|
@@ -16,3 +32,68 @@ medium-traffic 0.7785 0.6453 0.7057 1187
|
|
16 |
```
|
17 |
|
18 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
base_model:
|
6 |
+
- google/siglip2-base-patch16-224
|
7 |
+
pipeline_tag: image-classification
|
8 |
+
library_name: transformers
|
9 |
+
tags:
|
10 |
+
- traffic
|
11 |
+
- dense
|
12 |
+
- classification
|
13 |
---
|
14 |
+

|
15 |
+
|
16 |
+
# **Traffic-Density-Classification**
|
17 |
+
> **Traffic-Density-Classification** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a single-label classification task. It is designed to classify images into **traffic density** categories using the **SiglipForImageClassification** architecture.
|
18 |
+
|
19 |
+
|
20 |
```py
|
21 |
Classification Report:
|
22 |
precision recall f1-score support
|
|
|
32 |
```
|
33 |
|
34 |

|
35 |
+
|
36 |
+
The model categorizes images into the following 4 classes:
|
37 |
+
- **Class 0:** "high-traffic"
|
38 |
+
- **Class 1:** "low-traffic"
|
39 |
+
- **Class 2:** "medium-traffic"
|
40 |
+
- **Class 3:** "no-traffic"
|
41 |
+
|
42 |
+
# **Run with Transformers🤗**
|
43 |
+
|
44 |
+
```python
|
45 |
+
!pip install -q transformers torch pillow gradio
|
46 |
+
```
|
47 |
+
|
48 |
+
```python
|
49 |
+
import gradio as gr
|
50 |
+
from transformers import AutoImageProcessor
|
51 |
+
from transformers import SiglipForImageClassification
|
52 |
+
from transformers.image_utils import load_image
|
53 |
+
from PIL import Image
|
54 |
+
import torch
|
55 |
+
|
56 |
+
# Load model and processor
|
57 |
+
model_name = "prithivMLmods/Traffic-Density-Classification"
|
58 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
59 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
60 |
+
|
61 |
+
def traffic_density_classification(image):
|
62 |
+
"""Predicts traffic density category for an image."""
|
63 |
+
image = Image.fromarray(image).convert("RGB")
|
64 |
+
inputs = processor(images=image, return_tensors="pt")
|
65 |
+
|
66 |
+
with torch.no_grad():
|
67 |
+
outputs = model(**inputs)
|
68 |
+
logits = outputs.logits
|
69 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
70 |
+
|
71 |
+
labels = {
|
72 |
+
"0": "high-traffic", "1": "low-traffic", "2": "medium-traffic", "3": "no-traffic"
|
73 |
+
}
|
74 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
75 |
+
|
76 |
+
return predictions
|
77 |
+
|
78 |
+
# Create Gradio interface
|
79 |
+
iface = gr.Interface(
|
80 |
+
fn=traffic_density_classification,
|
81 |
+
inputs=gr.Image(type="numpy"),
|
82 |
+
outputs=gr.Label(label="Prediction Scores"),
|
83 |
+
title="Traffic Density Classification",
|
84 |
+
description="Upload an image to classify it into one of the 4 traffic density categories."
|
85 |
+
)
|
86 |
+
|
87 |
+
# Launch the app
|
88 |
+
if __name__ == "__main__":
|
89 |
+
iface.launch()
|
90 |
+
```
|
91 |
+
|
92 |
+
# **Intended Use:**
|
93 |
+
|
94 |
+
The **Traffic-Density-Classification** model is designed for traffic image classification. It helps categorize traffic density levels into predefined categories. Potential use cases include:
|
95 |
+
|
96 |
+
- **Traffic Monitoring:** Classifying images from traffic cameras to assess congestion levels.
|
97 |
+
- **Smart City Applications:** Assisting in traffic flow management and congestion reduction strategies.
|
98 |
+
- **Automated Traffic Analysis:** Helping transportation authorities analyze and optimize road usage.
|
99 |
+
- **AI Research:** Supporting computer vision-based traffic density classification models.
|