Update README.md
Browse files
README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
```py
|
| 5 |
Classification Report:
|
| 6 |
precision recall f1-score support
|
|
@@ -17,3 +22,67 @@ weighted avg 0.9918 0.9918 0.9918 5712
|
|
| 17 |
|
| 18 |

|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
# **BrainTumor-Classification-Mini**
|
| 6 |
+
> **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.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
```py
|
| 10 |
Classification Report:
|
| 11 |
precision recall f1-score support
|
|
|
|
| 22 |
|
| 23 |

|
| 24 |
|
| 25 |
+
The model categorizes images into the following 4 classes:
|
| 26 |
+
- **Class 0:** "No Tumor"
|
| 27 |
+
- **Class 1:** "Glioma"
|
| 28 |
+
- **Class 2:** "Meningioma"
|
| 29 |
+
- **Class 3:** "Pituitary"
|
| 30 |
+
|
| 31 |
+
# **Run with Transformers🤗**
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
!pip install -q transformers torch pillow gradio
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
import gradio as gr
|
| 39 |
+
from transformers import AutoImageProcessor
|
| 40 |
+
from transformers import SiglipForImageClassification
|
| 41 |
+
from transformers.image_utils import load_image
|
| 42 |
+
from PIL import Image
|
| 43 |
+
import torch
|
| 44 |
+
|
| 45 |
+
# Load model and processor
|
| 46 |
+
model_name = "prithivMLmods/BrainTumor-Classification-Mini"
|
| 47 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
| 48 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 49 |
+
|
| 50 |
+
def brain_tumor_classification(image):
|
| 51 |
+
"""Predicts brain tumor category for an image."""
|
| 52 |
+
image = Image.fromarray(image).convert("RGB")
|
| 53 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 54 |
+
|
| 55 |
+
with torch.no_grad():
|
| 56 |
+
outputs = model(**inputs)
|
| 57 |
+
logits = outputs.logits
|
| 58 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 59 |
+
|
| 60 |
+
labels = {
|
| 61 |
+
"0": "No Tumor", "1": "Glioma", "2": "Meningioma", "3": "Pituitary"
|
| 62 |
+
}
|
| 63 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
| 64 |
+
|
| 65 |
+
return predictions
|
| 66 |
+
|
| 67 |
+
# Create Gradio interface
|
| 68 |
+
iface = gr.Interface(
|
| 69 |
+
fn=brain_tumor_classification,
|
| 70 |
+
inputs=gr.Image(type="numpy"),
|
| 71 |
+
outputs=gr.Label(label="Prediction Scores"),
|
| 72 |
+
title="Brain Tumor Classification",
|
| 73 |
+
description="Upload an image to classify it into one of the 4 brain tumor categories."
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Launch the app
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
iface.launch()
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
# **Intended Use:**
|
| 82 |
+
|
| 83 |
+
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:
|
| 84 |
+
|
| 85 |
+
- **Medical Diagnosis Assistance:** Supporting radiologists in preliminary tumor classification.
|
| 86 |
+
- **AI-Assisted Healthcare:** Enhancing automated tumor detection in medical imaging.
|
| 87 |
+
- **Research & Development:** Facilitating studies in AI-driven medical imaging solutions.
|
| 88 |
+
- **Educational Purposes:** Helping students and professionals learn about tumor classification using AI.
|