Update README.md
Browse files
README.md
CHANGED
|
@@ -19,6 +19,10 @@ tags:
|
|
| 19 |
- street
|
| 20 |
---
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
```py
|
| 23 |
Classification Report:
|
| 24 |
precision recall f1-score support
|
|
@@ -36,3 +40,91 @@ weighted avg 0.9729 0.9728 0.9728 16345
|
|
| 36 |
```
|
| 37 |
|
| 38 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
- street
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# open-scene-detection
|
| 23 |
+
|
| 24 |
+
> open-scene-detection is a vision-language encoder model fine-tuned from [`siglip2-base-patch16-512`](https://huggingface.co/google/siglip-base-patch16-512) for multi-class scene classification. It is trained to recognize and categorize natural and urban scenes using a curated visual dataset. The model uses the `SiglipForImageClassification` architecture.
|
| 25 |
+
|
| 26 |
```py
|
| 27 |
Classification Report:
|
| 28 |
precision recall f1-score support
|
|
|
|
| 40 |
```
|
| 41 |
|
| 42 |

|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## Label Space: 6 Classes
|
| 47 |
+
|
| 48 |
+
The model classifies an image into one of the following scenes:
|
| 49 |
+
|
| 50 |
+
```
|
| 51 |
+
Class 0: Buildings
|
| 52 |
+
Class 1: Forest
|
| 53 |
+
Class 2: Glacier
|
| 54 |
+
Class 3: Mountain
|
| 55 |
+
Class 4: Sea
|
| 56 |
+
Class 5: Street
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## Install Dependencies
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
pip install -q transformers torch pillow gradio hf_xet
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
---
|
| 68 |
+
|
| 69 |
+
## Inference Code
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
import gradio as gr
|
| 73 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
| 74 |
+
from PIL import Image
|
| 75 |
+
import torch
|
| 76 |
+
|
| 77 |
+
# Load model and processor
|
| 78 |
+
model_name = "prithivMLmods/open-scene-detection" # Updated model name
|
| 79 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
| 80 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 81 |
+
|
| 82 |
+
# Updated label mapping
|
| 83 |
+
id2label = {
|
| 84 |
+
"0": "Buildings",
|
| 85 |
+
"1": "Forest",
|
| 86 |
+
"2": "Glacier",
|
| 87 |
+
"3": "Mountain",
|
| 88 |
+
"4": "Sea",
|
| 89 |
+
"5": "Street"
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
def classify_image(image):
|
| 93 |
+
image = Image.fromarray(image).convert("RGB")
|
| 94 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 95 |
+
|
| 96 |
+
with torch.no_grad():
|
| 97 |
+
outputs = model(**inputs)
|
| 98 |
+
logits = outputs.logits
|
| 99 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 100 |
+
|
| 101 |
+
prediction = {
|
| 102 |
+
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
return prediction
|
| 106 |
+
|
| 107 |
+
# Gradio Interface
|
| 108 |
+
iface = gr.Interface(
|
| 109 |
+
fn=classify_image,
|
| 110 |
+
inputs=gr.Image(type="numpy"),
|
| 111 |
+
outputs=gr.Label(num_top_classes=6, label="Scene Classification"),
|
| 112 |
+
title="open-scene-detection",
|
| 113 |
+
description="Upload an image to classify the scene into one of six categories: Buildings, Forest, Glacier, Mountain, Sea, or Street."
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
if __name__ == "__main__":
|
| 117 |
+
iface.launch()
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
## Intended Use
|
| 123 |
+
|
| 124 |
+
`open-scene-detection` is designed for:
|
| 125 |
+
|
| 126 |
+
* **Scene Recognition** – Automatically classify natural and urban scenes.
|
| 127 |
+
* **Environmental Mapping** – Support geographic and ecological analysis from visual data.
|
| 128 |
+
* **Dataset Annotation** – Efficiently label large-scale image datasets by scene.
|
| 129 |
+
* **Visual Search and Organization** – Enable smart scene-based filtering or retrieval.
|
| 130 |
+
* **Autonomous Systems** – Assist navigation and perception modules with scene understanding.
|