1 Classification Report :
2 precision recall f1 - score support
3
4 tench 0.9885 0.9834 0.9859 963
5 english springer 0.9843 0.9822 0.9832 955
6 cassette player 0.9544 0.9486 0.9515 993
7 chain saw 0.9257 0.8998 0.9125 858
8 church 0.9654 0.9798 0.9726 941
9 French horn 0.9757 0.9665 0.9711 956
10 garbage truck 0.8883 0.9761 0.9301 961
11 gas pump 0.9366 0.9044 0.9202 931
12 golf ball 0.9925 0.9716 0.9819 951
13 parachute 0.9821 0.9708 0.9764 960
14
15 accuracy 0.9590 9469
16 macro avg 0.9593 0.9583 0.9586 9469
17 weighted avg 0.9597 0.9590 0.9591 9469
0: tench
1: english springer
2: cassette player
3: chain saw
4: church
5: French horn
6: garbage truck
7: gas pump
8: golf ball
9: parachute
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/IMAGENETTE"
8 model = SiglipForImageClassification . from_pretrained ( model_name )
9 processor = AutoImageProcessor . from_pretrained ( model_name )
10
11 # Label mapping
12 id2label = {
13 "0" : "tench" ,
14 "1" : "english springer" ,
15 "2" : "cassette player" ,
16 "3" : "chain saw" ,
17 "4" : "church" ,
18 "5" : "French horn" ,
19 "6" : "garbage truck" ,
20 "7" : "gas pump" ,
21 "8" : "golf ball" ,
22 "9" : "parachute"
23 }
24
25 def classify_image ( image ) :
26 image = Image . fromarray ( image ) . convert ( "RGB" )
27 inputs = processor ( images = image , return_tensors = "pt" )
28
29 with torch . no_grad ( ) :
30 outputs = model ( ** inputs )
31 logits = outputs . logits
32 probs = torch . nn . functional . softmax ( logits , dim = 1 ) . squeeze ( ) . tolist ( )
33
34 prediction = {
35 id2label [ str ( i ) ] : round ( probs [ i ] , 3 ) for i in range ( len ( probs ) )
36 }
37
38 return prediction
39
40 # Gradio Interface
41 iface = gr . Interface (
42 fn = classify_image ,
43 inputs = gr . Image ( type = "numpy" ) ,
44 outputs = gr . Label ( num_top_classes = 3 , label = "Image Classification" ) ,
45 title = "IMAGENETTE - SigLIP2 Classifier" ,
46 description = "Upload an image to classify it into one of 10 categories from the Imagenette dataset."
47 )
48
49 if __name__ == "__main__" :
50 iface . launch ( )