prithivMLmods/Weather-Image-Classification
2756
1---2license: apache-2.03datasets:4- prithivMLmods/WeatherNet-055library_name: transformers6language:7- en8base_model:9- google/siglip2-base-patch16-22410pipeline_tag: image-classification11tags:12- Weather-Detection13- SigLIP214- 93M15---16 1718 19# Weather-Image-Classification20 21> Weather-Image-Classification is a vision-language model fine-tuned from google/siglip2-base-patch16-224 for multi-class image classification. It is trained to recognize weather conditions from images using the SiglipForImageClassification architecture.22 23```py24Classification Report:25 precision recall f1-score support26 27cloudy/overcast 0.8493 0.8762 0.8625 670228 foggy/hazy 0.8340 0.8128 0.8233 126129 rain/strom 0.7644 0.7592 0.7618 192730 snow/frosty 0.8341 0.8448 0.8394 187531 sun/clear 0.9124 0.8846 0.8983 627432 33 accuracy 0.8589 1803934 macro avg 0.8388 0.8355 0.8371 1803935 weighted avg 0.8595 0.8589 0.8591 1803936```37 3839 40---41 42## Label Space: 5 Classes43 44The model classifies an image into one of the following weather categories:45 46```json47"id2label": {48 "0": "cloudy/overcast",49 "1": "foggy/hazy",50 "2": "rain/storm",51 "3": "snow/frosty",52 "4": "sun/clear"53}54```55 56---57 58## Install Dependencies59 60```bash61pip install -q transformers torch pillow gradio62```63 64---65 66## Inference Code67 68```python69import gradio as gr70from transformers import AutoImageProcessor, SiglipForImageClassification71from PIL import Image72import torch73 74# Load model and processor75model_name = "prithivMLmods/Weather-Image-Classification" # Replace with actual path76model = SiglipForImageClassification.from_pretrained(model_name)77processor = AutoImageProcessor.from_pretrained(model_name)78 79# Label mapping80id2label = {81 "0": "cloudy/overcast",82 "1": "foggy/hazy",83 "2": "rain/storm",84 "3": "snow/frosty",85 "4": "sun/clear"86}87 88def classify_weather(image):89 image = Image.fromarray(image).convert("RGB")90 inputs = processor(images=image, return_tensors="pt")91 92 with torch.no_grad():93 outputs = model(**inputs)94 logits = outputs.logits95 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()96 97 prediction = {98 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))99 }100 101 return prediction102 103# Gradio Interface104iface = gr.Interface(105 fn=classify_weather,106 inputs=gr.Image(type="numpy"),107 outputs=gr.Label(num_top_classes=5, label="Weather Condition"),108 title="Weather-Image-Classification",109 description="Upload an image to identify the weather condition (sun, rain, snow, fog, or clouds)."110)111 112if __name__ == "__main__":113 iface.launch()114```115 116---117 118## Intended Use119 120Weather-Image-Classification is useful for:121 122* Automated weather tagging for photography and media.123* Enhancing dataset labeling in weather-related research.124* Supporting smart surveillance and traffic systems.125* Improving scene understanding in autonomous vehicles. 