Update README.md
Browse files
README.md
CHANGED
|
@@ -9,6 +9,61 @@ library_name: transformers
|
|
| 9 |
tags:
|
| 10 |
- fire-detection
|
| 11 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
Classification report:
|
| 13 |
|
| 14 |
precision recall f1-score support
|
|
@@ -19,4 +74,14 @@ tags:
|
|
| 19 |
|
| 20 |
accuracy 0.9941 3030
|
| 21 |
macro avg 0.9941 0.9941 0.9941 3030
|
| 22 |
-
weighted avg 0.9941 0.9941 0.9941 3030
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
tags:
|
| 10 |
- fire-detection
|
| 11 |
---
|
| 12 |
+
# **Fire-Detection-Siglip2**
|
| 13 |
+
|
| 14 |
+
**Fire-Detection-Siglip2** 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 detect fire, smoke, or normal conditions using the SiglipForImageClassification architecture.
|
| 15 |
+
|
| 16 |
+
The model categorizes images into three classes:
|
| 17 |
+
- **Class 0:** "Fire" – The image shows active fire.
|
| 18 |
+
- **Class 1:** "Normal" – The image depicts a normal, fire-free environment.
|
| 19 |
+
- **Class 2:** "Smoke" – The image contains visible smoke, indicating potential fire risk.
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
!pip install -q transformers torch pillow gradio
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
import gradio as gr
|
| 27 |
+
from transformers import AutoImageProcessor
|
| 28 |
+
from transformers import SiglipForImageClassification
|
| 29 |
+
from transformers.image_utils import load_image
|
| 30 |
+
from PIL import Image
|
| 31 |
+
import torch
|
| 32 |
+
|
| 33 |
+
# Load model and processor
|
| 34 |
+
model_name = "prithivMLmods/Fire-Detection-Siglip2"
|
| 35 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
| 36 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 37 |
+
|
| 38 |
+
def fire_detection(image):
|
| 39 |
+
"""Classifies an image as fire, smoke, or normal conditions."""
|
| 40 |
+
image = Image.fromarray(image).convert("RGB")
|
| 41 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 42 |
+
|
| 43 |
+
with torch.no_grad():
|
| 44 |
+
outputs = model(**inputs)
|
| 45 |
+
logits = outputs.logits
|
| 46 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 47 |
+
|
| 48 |
+
labels = model.config.id2label
|
| 49 |
+
predictions = {labels[i]: round(probs[i], 3) for i in range(len(probs))}
|
| 50 |
+
|
| 51 |
+
return predictions
|
| 52 |
+
|
| 53 |
+
# Create Gradio interface
|
| 54 |
+
iface = gr.Interface(
|
| 55 |
+
fn=fire_detection,
|
| 56 |
+
inputs=gr.Image(type="numpy"),
|
| 57 |
+
outputs=gr.Label(label="Detection Result"),
|
| 58 |
+
title="Fire Detection Model",
|
| 59 |
+
description="Upload an image to determine if it contains fire, smoke, or a normal condition."
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Launch the app
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
iface.launch()
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
Classification report:
|
| 68 |
|
| 69 |
precision recall f1-score support
|
|
|
|
| 74 |
|
| 75 |
accuracy 0.9941 3030
|
| 76 |
macro avg 0.9941 0.9941 0.9941 3030
|
| 77 |
+
weighted avg 0.9941 0.9941 0.9941 3030
|
| 78 |
+
|
| 79 |
+
# **Intended Use:**
|
| 80 |
+
|
| 81 |
+
The **Fire-Detection-Siglip2** model is designed to classify images into three categories: **fire, smoke, or normal conditions**. It helps in early fire detection and environmental monitoring.
|
| 82 |
+
|
| 83 |
+
### Potential Use Cases:
|
| 84 |
+
- **Fire Safety Monitoring:** Detecting fire and smoke in surveillance footage.
|
| 85 |
+
- **Early Warning Systems:** Helping in real-time fire hazard detection in public and private areas.
|
| 86 |
+
- **Disaster Prevention:** Assisting emergency response teams by identifying fire-prone areas.
|
| 87 |
+
- **Smart Home & IoT Integration:** Enhancing automated fire alert systems in smart security setups.
|