SigLIP2 070225, 070125
Collection
new exps
โข
3 items
โข
Updated
Brain3-Anomaly-SigLIP2 is a vision-language encoder model fine-tuned from google/siglip2-base-patch16-224 for multi-class medical image classification. It is trained to distinguish between different types of brain anomalies using the SiglipForImageClassification architecture.
Classification Report:
precision recall f1-score support
brain_glioma 0.9853 0.9725 0.9789 2000
brain_menin 0.9361 0.9735 0.9544 2000
brain_tumor 0.9743 0.9480 0.9610 2000
accuracy 0.9647 6000
macro avg 0.9652 0.9647 0.9647 6000
weighted avg 0.9652 0.9647 0.9647 6000
The model classifies each image into one of the following categories:
0: brain_glioma
1: brain_menin
2: brain_tumor
pip install -q transformers torch pillow gradio
import gradio as gr
from transformers import AutoImageProcessor, SiglipForImageClassification
from PIL import Image
import torch
# Load model and processor
model_name = "prithivMLmods/Brain3-Anomaly-SigLIP2" # Replace with your model path if different
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)
# Label mapping
id2label = {
"0": "brain_glioma",
"1": "brain_menin",
"2": "brain_tumor"
}
def classify_brain_anomaly(image):
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
prediction = {
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
}
return prediction
# Gradio Interface
iface = gr.Interface(
fn=classify_brain_anomaly,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(num_top_classes=3, label="Brain Anomaly Classification"),
title="Brain3-Anomaly-SigLIP2",
description="Upload a brain scan image to classify it as glioma, meningioma, or tumor."
)
if __name__ == "__main__":
iface.launch()
Brain3-Anomaly-SigLIP2 can be used for:
Base model
google/siglip2-base-patch16-224