Views
No views yet

Flood-Image-Detection is a vision-language encoder model fine-tuned fromgoogle/siglip2-base-patch16-512for binary image classification. It is trained to detect whether an image contains a flooded scene or non-flooded environment. The model uses theSiglipForImageClassificationarchitecture.
[!note] SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features : https://arxiv.org/pdf/2502.14786
1Classification Report:
2 precision recall f1-score support
3
4Flooded Scene 0.9172 0.9458 0.9313 609
5 Non Flooded 0.9744 0.9603 0.9673 1309
6
7 accuracy 0.9557 1918
8 macro avg 0.9458 0.9530 0.9493 1918
9 weighted avg 0.9562 0.9557 0.9559 1918
Class 0: Flooded Scene
Class 1: Non Floodedpip install -q transformers torch pillow gradio hf_xet1import gradio as gr
2from transformers import AutoImageProcessor, SiglipForImageClassification
3from PIL import Image
4import torch
5
6# Load model and processor
7model_name = "prithivMLmods/flood-image-detection" # Update with actual model name on Hugging Face
8model = SiglipForImageClassification.from_pretrained(model_name)
9processor = AutoImageProcessor.from_pretrained(model_name)
10
11# Updated label mapping
12id2label = {
13 "0": "Flooded Scene",
14 "1": "Non Flooded"
15}
16
17def classify_image(image):
18 image = Image.fromarray(image).convert("RGB")
19 inputs = processor(images=image, return_tensors="pt")
20
21 with torch.no_grad():
22 outputs = model(**inputs)
23 logits = outputs.logits
24 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
25
26 prediction = {
27 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
28 }
29
30 return prediction
31
32# Gradio Interface
33iface = gr.Interface(
34 fn=classify_image,
35 inputs=gr.Image(type="numpy"),
36 outputs=gr.Label(num_top_classes=2, label="Flood Detection"),
37 title="Flood-Image-Detection",
38 description="Upload an image to detect whether the scene is flooded or not."
39)
40
41if __name__ == "__main__":
42 iface.launch()Flood-Image-Detection is designed for: