File size: 3,252 Bytes
ba3ca2d
 
28e974a
 
 
 
 
 
 
 
ba3ca2d
4e64d82
 
 
 
 
 
 
 
 
71a6fdb
 
4e64d82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba3ca2d
 
 
 
 
 
 
 
 
 
4e64d82
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
license: apache-2.0
language:
- en
base_model:
- google/siglip2-base-patch16-224
pipeline_tag: image-classification
library_name: transformers
tags:
- fire-detection
---
#  **Fire-Detection-Siglip2**  

**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.  

The model categorizes images into three classes:  
- **Class 0:** "Fire" – The image shows active fire.  
- **Class 1:** "Normal" – The image depicts a normal, fire-free environment.  
- **Class 2:** "Smoke" – The image contains visible smoke, indicating potential fire risk.  

# **Run with Transformers🤗**

```python
!pip install -q transformers torch pillow gradio
```

```python
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch

# Load model and processor
model_name = "prithivMLmods/Fire-Detection-Siglip2"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)

def fire_detection(image):
    """Classifies an image as fire, smoke, or normal conditions."""
    image = Image.fromarray(image).convert("RGB")
    inputs = processor(images=image, return_tensors="pt")
    
    with torch.no_grad():
        outputs = model(**inputs)
        logits = outputs.logits
        probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
    
    labels = model.config.id2label
    predictions = {labels[i]: round(probs[i], 3) for i in range(len(probs))}
    
    return predictions

# Create Gradio interface
iface = gr.Interface(
    fn=fire_detection,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Label(label="Detection Result"),
    title="Fire Detection Model",
    description="Upload an image to determine if it contains fire, smoke, or a normal condition."
)

# Launch the app
if __name__ == "__main__":
    iface.launch()
```

    Classification report:
    
                  precision    recall  f1-score   support
    
            fire     0.9940    0.9881    0.9911      1010
          normal     0.9892    0.9941    0.9916      1010
           smoke     0.9990    1.0000    0.9995      1010
    
        accuracy                         0.9941      3030
       macro avg     0.9941    0.9941    0.9941      3030
    weighted avg     0.9941    0.9941    0.9941      3030

# **Intended Use:**  

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.  

### Potential Use Cases:  
- **Fire Safety Monitoring:** Detecting fire and smoke in surveillance footage.  
- **Early Warning Systems:** Helping in real-time fire hazard detection in public and private areas.  
- **Disaster Prevention:** Assisting emergency response teams by identifying fire-prone areas.  
- **Smart Home & IoT Integration:** Enhancing automated fire alert systems in smart security setups.