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