File size: 3,307 Bytes
b020a0d
 
 
 
f5f19ef
 
 
 
 
 
 
 
 
 
 
 
ad18f31
 
f5f19ef
 
 
 
 
 
ad18f31
 
 
 
 
 
 
 
 
 
 
 
 
 
f5f19ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
license: apache-2.0
datasets:
- prithivMLmods/Brain3-Anomaly-Classification
language:
- en
base_model:
- google/siglip2-base-patch16-224
pipeline_tag: image-classification
library_name: transformers
tags:
- brain
- tumor
- biology
- chemistry
- medical
---

![b3.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/LvOpYoEOjWPr9bozOAaBE.png)

# **Brain3-Anomaly-SigLIP2**

> **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.

```py
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
```

![download (1).png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/-YBXtGneTQ6BrB9o5YiZ-.png)

---

## **Label Space: 3 Classes**

The model classifies each image into one of the following categories:

```
0: brain_glioma
1: brain_menin
2: brain_tumor
```

---

## **Install Dependencies**

```bash
pip install -q transformers torch pillow gradio
```

---

## **Inference Code**

```python
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()
```

---

## **Intended Use**

**Brain3-Anomaly-SigLIP2** can be used for:

* **Medical Diagnostics Support** – Assisting radiologists in identifying brain anomalies from MRI or CT images.
* **Academic Research** – Supporting experiments in brain tumor classification tasks.
* **Medical AI Prototyping** – Useful for healthcare AI pipelines involving limited anomaly classes.
* **Dataset Annotation** – Pre-label brain images for manual review or semi-supervised learning.