Views
No views yet
| Property | Value |
|---|---|
| Base Model | 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 |
masoudnickparvar/brain-tumor-mri-dataset, AIOmarRehan/Brain_Tumor_MRI_Dataset, sartajbhuvaji/Brain-Tumor-Classificationtrain_test_split(test_size=0.15, seed=42)| 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. |
| 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%) |
| 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 |
| Property | Value |
|---|---|
| GPU | NVIDIA L4 (24 GB VRAM) |
| Cloud Platform | Modal serverless GPU |
| Training Time | ~30-45 minutes |
| Final Training Loss | 0.1026 |
Analyze this brain MRI and classify the finding.
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).
1from transformers import AutoProcessor, AutoModelForImageTextToText
2from peft import PeftModel
3from PIL import Image
4
5base_model_id = "google/medgemma-4b-it"
6adapter_id = "efecelik/medgemma-brain-mri-lora"
7
8processor = AutoProcessor.from_pretrained(base_model_id)
9model = AutoModelForImageTextToText.from_pretrained(
10 base_model_id, torch_dtype="bfloat16", device_map="auto"
11)
12model = PeftModel.from_pretrained(model, adapter_id)
13
14image = Image.open("brain_mri.jpg").convert("RGB")
15messages = [
16 {"role": "user", "content": [
17 {"type": "image"},
18 {"type": "text", "text": "Analyze this brain MRI and classify the finding."}
19 ]}
20]
21
22inputs = processor.apply_chat_template(
23 messages, add_generation_prompt=True, tokenize=True,
24 return_dict=True, return_tensors="pt", images=[image]
25).to(model.device)
26
27output = model.generate(**inputs, max_new_tokens=256)
28print(processor.decode(output[0], skip_special_tokens=True))