Add model card with training details and usage instructions
Browse files
README.md
CHANGED
|
@@ -1,199 +1,154 @@
|
|
| 1 |
---
|
| 2 |
-
library_name:
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
|
| 159 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
###
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
###
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
##
|
| 172 |
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
| 176 |
|
| 177 |
-
|
|
|
|
| 178 |
|
| 179 |
-
**
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
|
|
|
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
library_name: peft
|
| 3 |
+
license: other
|
| 4 |
+
license_name: health-ai-developer-foundations
|
| 5 |
+
license_link: https://developers.google.com/health-ai-developer-foundations/terms
|
| 6 |
+
base_model: google/medgemma-4b-it
|
| 7 |
+
tags:
|
| 8 |
+
- medgemma
|
| 9 |
+
- lora
|
| 10 |
+
- medical-ai
|
| 11 |
+
- brain-mri
|
| 12 |
+
- brain-tumor-classification
|
| 13 |
+
- hai-def
|
| 14 |
+
- neuroimaging
|
| 15 |
+
datasets:
|
| 16 |
+
- sartajbhuvaji/Brain-Tumor-Classification
|
| 17 |
+
language:
|
| 18 |
+
- en
|
| 19 |
+
pipeline_tag: image-text-to-text
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# MedGemma Brain MRI LoRA
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
**Brain tumor classification adapter fine-tuned on Brain Tumor MRI dataset using MedGemma 4B.**
|
| 25 |
|
| 26 |
+
Classifies brain MRI images into 4 categories: glioma, meningioma, pituitary tumor, or no tumor.
|
| 27 |
|
| 28 |
## Model Details
|
| 29 |
|
| 30 |
+
| Property | Value |
|
| 31 |
+
|----------|-------|
|
| 32 |
+
| **Base Model** | [google/medgemma-4b-it](https://huggingface.co/google/medgemma-4b-it) |
|
| 33 |
+
| **Method** | LoRA (Low-Rank Adaptation) |
|
| 34 |
+
| **Task** | Multi-class brain tumor classification (4 classes) |
|
| 35 |
+
| **Modality** | Brain MRI |
|
| 36 |
+
| **Framework** | PyTorch + HuggingFace Transformers + PEFT |
|
| 37 |
+
|
| 38 |
+
## Training Dataset
|
| 39 |
+
|
| 40 |
+
**Brain Tumor MRI Classification** dataset — multi-source brain MRI collection for tumor type classification.
|
| 41 |
+
|
| 42 |
+
Fallback sources tried in order: `masoudnickparvar/brain-tumor-mri-dataset`, `AIOmarRehan/Brain_Tumor_MRI_Dataset`, `sartajbhuvaji/Brain-Tumor-Classification`
|
| 43 |
+
|
| 44 |
+
- **Train samples:** ~5,700 (85% split)
|
| 45 |
+
- **Validation samples:** ~1,000 (15% split)
|
| 46 |
+
- **Split strategy:** `train_test_split(test_size=0.15, seed=42)`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
### Class Distribution
|
| 49 |
+
|
| 50 |
+
| Label | Description |
|
| 51 |
+
|-------|-------------|
|
| 52 |
+
| glioma | Malignant tumor from glial cells. Irregular, heterogeneous mass with surrounding edema. Most common primary malignant brain tumor. |
|
| 53 |
+
| meningioma | Typically benign tumor from the meninges. Well-defined, homogeneously enhancing extra-axial mass with dural tail sign. |
|
| 54 |
+
| pituitary | Adenoma from the pituitary gland in the sella turcica. May compress the optic chiasm causing visual field defects. |
|
| 55 |
+
| notumor | Normal brain MRI without intracranial mass, hemorrhage, or significant abnormality. |
|
| 56 |
|
| 57 |
+
## Training Configuration
|
| 58 |
|
| 59 |
+
### LoRA Parameters
|
| 60 |
|
| 61 |
+
| Parameter | Value |
|
| 62 |
+
|-----------|-------|
|
| 63 |
+
| Rank (r) | 16 |
|
| 64 |
+
| Alpha | 32 |
|
| 65 |
+
| Dropout | 0.05 |
|
| 66 |
+
| Target Modules | all-linear |
|
| 67 |
+
| Task Type | CAUSAL_LM |
|
| 68 |
+
| Trainable Params | 1.38B / 5.68B (24.3%) |
|
| 69 |
|
| 70 |
+
### Hyperparameters
|
| 71 |
|
| 72 |
+
| Parameter | Value |
|
| 73 |
+
|-----------|-------|
|
| 74 |
+
| Epochs | 1 |
|
| 75 |
+
| Per-device Batch Size | 1 |
|
| 76 |
+
| Gradient Accumulation Steps | 8 (effective batch = 8) |
|
| 77 |
+
| Learning Rate | 2e-4 |
|
| 78 |
+
| LR Scheduler | Linear with warmup |
|
| 79 |
+
| Warmup Ratio | 0.03 |
|
| 80 |
+
| Max Grad Norm | 0.3 |
|
| 81 |
+
| Precision | bfloat16 |
|
| 82 |
+
| Gradient Checkpointing | Enabled |
|
| 83 |
+
| Seed | 42 |
|
| 84 |
|
| 85 |
+
### Infrastructure
|
| 86 |
|
| 87 |
+
| Property | Value |
|
| 88 |
+
|----------|-------|
|
| 89 |
+
| GPU | NVIDIA L4 (24 GB VRAM) |
|
| 90 |
+
| Cloud Platform | [Modal](https://modal.com) serverless GPU |
|
| 91 |
+
| Training Time | ~30-45 minutes |
|
| 92 |
+
| Final Training Loss | 0.1026 |
|
| 93 |
|
| 94 |
+
## Prompt Format
|
| 95 |
|
| 96 |
+
**Input:**
|
| 97 |
+
> Analyze this brain MRI and classify the finding.
|
| 98 |
|
| 99 |
+
**Output:**
|
| 100 |
+
> This brain MRI shows **Meningioma**.
|
| 101 |
+
>
|
| 102 |
+
> Meningioma (typically benign tumor arising from the meninges. Appears as a well-defined, homogeneously enhancing extra-axial mass, often with a dural tail sign).
|
| 103 |
|
| 104 |
+
## Usage
|
| 105 |
|
| 106 |
+
```python
|
| 107 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 108 |
+
from peft import PeftModel
|
| 109 |
+
from PIL import Image
|
| 110 |
|
| 111 |
+
base_model_id = "google/medgemma-4b-it"
|
| 112 |
+
adapter_id = "efecelik/medgemma-brain-mri-lora"
|
| 113 |
|
| 114 |
+
processor = AutoProcessor.from_pretrained(base_model_id)
|
| 115 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 116 |
+
base_model_id, torch_dtype="bfloat16", device_map="auto"
|
| 117 |
+
)
|
| 118 |
+
model = PeftModel.from_pretrained(model, adapter_id)
|
| 119 |
|
| 120 |
+
image = Image.open("brain_mri.jpg").convert("RGB")
|
| 121 |
+
messages = [
|
| 122 |
+
{"role": "user", "content": [
|
| 123 |
+
{"type": "image"},
|
| 124 |
+
{"type": "text", "text": "Analyze this brain MRI and classify the finding."}
|
| 125 |
+
]}
|
| 126 |
+
]
|
| 127 |
|
| 128 |
+
inputs = processor.apply_chat_template(
|
| 129 |
+
messages, add_generation_prompt=True, tokenize=True,
|
| 130 |
+
return_dict=True, return_tensors="pt", images=[image]
|
| 131 |
+
).to(model.device)
|
| 132 |
|
| 133 |
+
output = model.generate(**inputs, max_new_tokens=256)
|
| 134 |
+
print(processor.decode(output[0], skip_special_tokens=True))
|
| 135 |
+
```
|
| 136 |
|
| 137 |
+
## Intended Use
|
| 138 |
|
| 139 |
+
This adapter is part of the **MedVision AI** platform built for the [MedGemma Impact Challenge](https://www.kaggle.com/competitions/med-gemma-impact-challenge). It is designed for:
|
| 140 |
|
| 141 |
+
- **Medical education**: Helping students learn brain tumor identification on MRI
|
| 142 |
+
- **Clinical decision support**: Assisting radiologists with brain lesion characterization
|
| 143 |
+
- **Research**: Exploring fine-tuned medical VLMs for neuroimaging
|
| 144 |
+
|
| 145 |
+
## Limitations
|
| 146 |
+
|
| 147 |
+
- **Not for clinical diagnosis.** This model is for educational and research purposes only.
|
| 148 |
+
- **Limited tumor types:** Only classifies 4 categories. Many brain pathologies (abscess, stroke, MS) are not covered.
|
| 149 |
+
- **Single sequence:** Trained on individual MRI slices, not full 3D volumes or multi-sequence protocols.
|
| 150 |
+
- **Single epoch:** Trained for 1 epoch; further training may improve performance.
|
| 151 |
+
|
| 152 |
+
## Disclaimer
|
| 153 |
+
|
| 154 |
+
This model is for **educational and research purposes only**. It is NOT intended for clinical diagnosis or patient care decisions. Always consult qualified medical professionals for medical advice.
|