--- library_name: peft license: other license_name: health-ai-developer-foundations license_link: https://developers.google.com/health-ai-developer-foundations/terms base_model: google/medgemma-4b-it tags: - medgemma - lora - medical-ai - brain-mri - brain-tumor-classification - hai-def - neuroimaging datasets: - sartajbhuvaji/Brain-Tumor-Classification language: - en pipeline_tag: image-text-to-text --- # MedGemma Brain MRI LoRA **Brain tumor classification adapter fine-tuned on Brain Tumor MRI dataset using MedGemma 4B.** Classifies brain MRI images into 4 categories: glioma, meningioma, pituitary tumor, or no tumor. ## Model Details | Property | Value | |----------|-------| | **Base Model** | [google/medgemma-4b-it](https://huggingface.co/google/medgemma-4b-it) | | **Method** | LoRA (Low-Rank Adaptation) | | **Task** | Multi-class brain tumor classification (4 classes) | | **Modality** | Brain MRI | | **Framework** | PyTorch + HuggingFace Transformers + PEFT | ## Training Dataset **Brain Tumor MRI Classification** dataset — multi-source brain MRI collection for tumor type classification. Fallback sources tried in order: `masoudnickparvar/brain-tumor-mri-dataset`, `AIOmarRehan/Brain_Tumor_MRI_Dataset`, `sartajbhuvaji/Brain-Tumor-Classification` - **Train samples:** ~5,700 (85% split) - **Validation samples:** ~1,000 (15% split) - **Split strategy:** `train_test_split(test_size=0.15, seed=42)` ### Class Distribution | Label | Description | |-------|-------------| | glioma | Malignant tumor from glial cells. Irregular, heterogeneous mass with surrounding edema. Most common primary malignant brain tumor. | | meningioma | Typically benign tumor from the meninges. Well-defined, homogeneously enhancing extra-axial mass with dural tail sign. | | pituitary | Adenoma from the pituitary gland in the sella turcica. May compress the optic chiasm causing visual field defects. | | notumor | Normal brain MRI without intracranial mass, hemorrhage, or significant abnormality. | ## Training Configuration ### LoRA Parameters | Parameter | Value | |-----------|-------| | Rank (r) | 16 | | Alpha | 32 | | Dropout | 0.05 | | Target Modules | all-linear | | Task Type | CAUSAL_LM | | Trainable Params | 1.38B / 5.68B (24.3%) | ### Hyperparameters | Parameter | Value | |-----------|-------| | Epochs | 1 | | Per-device Batch Size | 1 | | Gradient Accumulation Steps | 8 (effective batch = 8) | | Learning Rate | 2e-4 | | LR Scheduler | Linear with warmup | | Warmup Ratio | 0.03 | | Max Grad Norm | 0.3 | | Precision | bfloat16 | | Gradient Checkpointing | Enabled | | Seed | 42 | ### Infrastructure | Property | Value | |----------|-------| | GPU | NVIDIA L4 (24 GB VRAM) | | Cloud Platform | [Modal](https://modal.com) serverless GPU | | Training Time | ~30-45 minutes | | Final Training Loss | 0.1026 | ## Prompt Format **Input:** > Analyze this brain MRI and classify the finding. **Output:** > This brain MRI shows **Meningioma**. > > Meningioma (typically benign tumor arising from the meninges. Appears as a well-defined, homogeneously enhancing extra-axial mass, often with a dural tail sign). ## Usage ```python from transformers import AutoProcessor, AutoModelForImageTextToText from peft import PeftModel from PIL import Image base_model_id = "google/medgemma-4b-it" adapter_id = "efecelik/medgemma-brain-mri-lora" processor = AutoProcessor.from_pretrained(base_model_id) model = AutoModelForImageTextToText.from_pretrained( base_model_id, torch_dtype="bfloat16", device_map="auto" ) model = PeftModel.from_pretrained(model, adapter_id) image = Image.open("brain_mri.jpg").convert("RGB") messages = [ {"role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "Analyze this brain MRI and classify the finding."} ]} ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", images=[image] ).to(model.device) output = model.generate(**inputs, max_new_tokens=256) print(processor.decode(output[0], skip_special_tokens=True)) ``` ## Intended Use 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: - **Medical education**: Helping students learn brain tumor identification on MRI - **Clinical decision support**: Assisting radiologists with brain lesion characterization - **Research**: Exploring fine-tuned medical VLMs for neuroimaging ## Limitations - **Not for clinical diagnosis.** This model is for educational and research purposes only. - **Limited tumor types:** Only classifies 4 categories. Many brain pathologies (abscess, stroke, MS) are not covered. - **Single sequence:** Trained on individual MRI slices, not full 3D volumes or multi-sequence protocols. - **Single epoch:** Trained for 1 epoch; further training may improve performance. ## Disclaimer 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.