1 Classification Report :
2 precision recall f1 - score support
3
4 buildings 0.9755 0.9570 0.9662 2625
5 forest 0.9989 0.9955 0.9972 2694
6 glacier 0.9564 0.9517 0.9540 2671
7 mountain 0.9540 0.9592 0.9566 2723
8 sea 0.9934 0.9898 0.9916 2758
9 street 0.9595 0.9819 0.9706 2874
10
11 accuracy 0.9728 16345
12 macro avg 0.9730 0.9725 0.9727 16345
13 weighted avg 0.9729 0.9728 0.9728 16345
Class 0: Buildings
Class 1: Forest
Class 2: Glacier
Class 3: Mountain
Class 4: Sea
Class 5: Street
1 import gradio as gr
2 from transformers import AutoImageProcessor , SiglipForImageClassification
3 from PIL import Image
4 import torch
5
6 # Load model and processor
7 model_name = "prithivMLmods/open-scene-detection" # Updated model name
8 model = SiglipForImageClassification . from_pretrained ( model_name )
9 processor = AutoImageProcessor . from_pretrained ( model_name )
10
11 # Updated label mapping
12 id2label = {
13 "0" : "Buildings" ,
14 "1" : "Forest" ,
15 "2" : "Glacier" ,
16 "3" : "Mountain" ,
17 "4" : "Sea" ,
18 "5" : "Street"
19 }
20
21 def classify_image ( image ) :
22 image = Image . fromarray ( image ) . convert ( "RGB" )
23 inputs = processor ( images = image , return_tensors = "pt" )
24
25 with torch . no_grad ( ) :
26 outputs = model ( ** inputs )
27 logits = outputs . logits
28 probs = torch . nn . functional . softmax ( logits , dim = 1 ) . squeeze ( ) . tolist ( )
29
30 prediction = {
31 id2label [ str ( i ) ] : round ( probs [ i ] , 3 ) for i in range ( len ( probs ) )
32 }
33
34 return prediction
35
36 # Gradio Interface
37 iface = gr . Interface (
38 fn = classify_image ,
39 inputs = gr . Image ( type = "numpy" ) ,
40 outputs = gr . Label ( num_top_classes = 6 , label = "Scene Classification" ) ,
41 title = "open-scene-detection" ,
42 description = "Upload an image to classify the scene into one of six categories: Buildings, Forest, Glacier, Mountain, Sea, or Street."
43 )
44
45 if __name__ == "__main__" :
46 iface . launch ( )