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

# **BrainTumor-Classification-Mini**
> **BrainTumor-Classification-Mini** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a single-label classification task. It is designed to classify brain tumor images using the **SiglipForImageClassification** architecture.  


```py
Classification Report:
              precision    recall  f1-score   support

    No Tumor     0.9975    0.9962    0.9969      1595
      Glioma     0.9872    0.9947    0.9910      1321
  Meningioma     0.9880    0.9821    0.9850      1339
   Pituitary     0.9931    0.9931    0.9931      1457

    accuracy                         0.9918      5712
   macro avg     0.9915    0.9915    0.9915      5712
weighted avg     0.9918    0.9918    0.9918      5712
```

![download.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/AzW7SbNOuh9cxrV-8Kq8q.png)

The model categorizes images into the following 4 classes:  
- **Class 0:** "No Tumor"  
- **Class 1:** "Glioma"  
- **Class 2:** "Meningioma"  
- **Class 3:** "Pituitary"  

# **Run with Transformers🤗**

```python
!pip install -q transformers torch pillow gradio
```

```python
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch

# Load model and processor
model_name = "prithivMLmods/BrainTumor-Classification-Mini"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)

def brain_tumor_classification(image):
    """Predicts brain tumor category for an 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()
    
    labels = {
        "0": "No Tumor", "1": "Glioma", "2": "Meningioma", "3": "Pituitary"
    }
    predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
    
    return predictions

# Create Gradio interface
iface = gr.Interface(
    fn=brain_tumor_classification,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Label(label="Prediction Scores"),
    title="Brain Tumor Classification",
    description="Upload an image to classify it into one of the 4 brain tumor categories."
)

# Launch the app
if __name__ == "__main__":
    iface.launch()
```

# **Intended Use:**  

The **BrainTumor-Classification-Mini** model is designed for brain tumor image classification. It helps categorize MRI images into predefined tumor types. Potential use cases include:  

- **Medical Diagnosis Assistance:** Supporting radiologists in preliminary tumor classification.  
- **AI-Assisted Healthcare:** Enhancing automated tumor detection in medical imaging.  
- **Research & Development:** Facilitating studies in AI-driven medical imaging solutions.  
- **Educational Purposes:** Helping students and professionals learn about tumor classification using AI.
no tumor glioma meningioma pituitary