MedGemma Musculoskeletal LoRA
Bone fracture detection adapter fine-tuned on fracture X-ray datasets using MedGemma 4B.
Binary classification of musculoskeletal X-rays: fractured vs. non-fractured, with optional body-part-specific context.
Model Details
| Property | Value |
|---|---|
| Base Model | google/medgemma-4b-it |
| Method | LoRA (Low-Rank Adaptation) |
| Task | Binary fracture classification |
| Modality | Musculoskeletal X-ray |
| Framework | PyTorch + HuggingFace Transformers + PEFT |
Training Dataset
Bone Fracture Detection — ~8.8K musculoskeletal X-ray images for binary fracture classification.
- Train samples: 8,000 (capped)
- Validation samples: 800
- Split strategy:
train_test_split(test_size=0.15, seed=42)
Class Labels
| Label | Description |
|---|---|
| fractured | Visible fracture line indicating cortical bone disruption. Pattern, location, and alignment should be characterized. |
| non-fractured | Intact cortical bone margins. No fracture line, displacement, or callus formation. Normal bone density and alignment. |
Body Regions Covered
Hand/wrist, shoulder, elbow, knee, ankle, hip, forearm, humerus, finger, leg/tibia-fibula
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 serverless GPU |
| Training Time | ~30-45 minutes |
Prompt Format
When body part information is available:
Input:
Analyze this hand/wrist X-ray for fracture.
Output:
Fracture detected.
There is a visible fracture line indicating disruption of cortical bone continuity. The fracture pattern, location, and alignment should be further characterized for treatment planning.
When body part is unknown:
Input:
Analyze this musculoskeletal X-ray for fracture.
Usage
from transformers import AutoProcessor, AutoModelForImageTextToText
from peft import PeftModel
from PIL import Image
base_model_id = "google/medgemma-4b-it"
adapter_id = "efecelik/medgemma-musculoskeletal-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("wrist_xray.jpg").convert("RGB")
messages = [
{"role": "user", "content": [
{"type": "image"},
{"type": "text", "text": "Analyze this wrist X-ray for fracture."}
]}
]
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. It is designed for:
- Medical education: Helping students learn fracture identification on X-rays
- Clinical decision support: Assisting emergency physicians with fracture screening
- Research: Exploring fine-tuned medical VLMs for musculoskeletal imaging
Limitations
- Not for clinical diagnosis. This model is for educational and research purposes only.
- Binary only: Classifies fracture vs. no-fracture. Does not characterize fracture type (comminuted, spiral, greenstick, etc.).
- Subtle fractures: May miss occult fractures (stress fractures, non-displaced fractures) that are challenging even for radiologists.
- Single epoch: Trained for 1 epoch; further training may improve performance.
- Mixed body regions: Performance may vary across different anatomical regions.
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.
- Downloads last month
- 18