Views
No views yet

MetaCLIP-2-Open-Scene is an image classification vision-language encoder model fine-tuned from facebook/metaclip-2-worldwide-s16 for a single-label classification task. It is designed to identify and categorize various natural and urban scenes using the MetaClip2ForImageClassification architecture.
[!note] MetaCLIP 2: A Worldwide Scaling Recipe : https://huggingface.co/papers/2507.22062
Classification Report:
precision recall f1-score support
buildings 0.9644 0.9703 0.9673 2625
forest 0.9948 0.9978 0.9963 2694
glacier 0.9531 0.9427 0.9479 2671
mountain 0.9470 0.9512 0.9491 2723
sea 0.9909 0.9920 0.9915 2758
street 0.9728 0.9694 0.9711 2874
accuracy 0.9706 16345
macro avg 0.9705 0.9706 0.9705 16345
weighted avg 0.9706 0.9706 0.9706 16345
!pip install -q transformers torch pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor
3from transformers import AutoModelForImageClassification
4from transformers.image_utils import load_image
5from PIL import Image
6import torch
7
8# Load model and processor
9model_name = "prithivMLmods/MetaCLIP-2-Open-Scene"
10model = AutoModelForImageClassification.from_pretrained(model_name)
11processor = AutoImageProcessor.from_pretrained(model_name)
12
13def scene_classification(image):
14 """Predicts the type of scene represented in an image."""
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 = {
24 "0": "buildings",
25 "1": "forest",
26 "2": "glacier",
27 "3": "mountain",
28 "4": "sea",
29 "5": "street"
30 }
31 predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
32
33 return predictions
34
35# Create Gradio interface
36iface = gr.Interface(
37 fn=scene_classification,
38 inputs=gr.Image(type="numpy"),
39 outputs=gr.Label(label="Prediction Scores"),
40 title="Open Scene Classification",
41 description="Upload an image to classify the scene type (e.g., forest, sea, street, mountain, etc.)."
42)
43
44# Launch the app
45if __name__ == "__main__":
46 iface.launch()



