Views
No views yet

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.
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!pip install -q transformers torch pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor
3from transformers import SiglipForImageClassification
4from transformers.image_utils import load_image
5from PIL import Image
6import torch
7
8# Load model and processor
9model_name = "prithivMLmods/Fire-Detection-Siglip2"
10model = SiglipForImageClassification.from_pretrained(model_name)
11processor = AutoImageProcessor.from_pretrained(model_name)
12
13def fire_detection(image):
14 """Classifies an image as fire, smoke, or normal conditions."""
15 image = Image.fromarray(image).convert("RGB")
16 inputs = processor(images=image, return_tensors="pt")
17
18 with torch.no_grad():
19 outputs = model(**inputs)
20 logits = outputs.logits
21 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
22
23 labels = model.config.id2label
24 predictions = {labels[i]: round(probs[i], 3) for i in range(len(probs))}
25
26 return predictions
27
28# Create Gradio interface
29iface = gr.Interface(
30 fn=fire_detection,
31 inputs=gr.Image(type="numpy"),
32 outputs=gr.Label(label="Detection Result"),
33 title="Fire Detection Model",
34 description="Upload an image to determine if it contains fire, smoke, or a normal condition."
35)
36
37# Launch the app
38if __name__ == "__main__":
39 iface.launch()