Downloads · 30 days
9
6% of all-time downloads
leoyinn/flare25-medgemma
flare25-medgemma is a image-text-to-text model from leoyinn. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
This model is a fine-tuned version of google/medgemma-4b-it specifically optimized for medical image analysis tasks in the FLARE 2025 2D Medical Multimodal Dataset challenge.
Downloads · 30 days
9
6% of all-time downloads
All-time downloads
140
Public
Repo size
165 MB
Likes
2
Public
Click a slice to open those files.
.safetensors131 MB · 79%
From the Hugging Face model README
This model is a fine-tuned version of google/medgemma-4b-it specifically optimized for medical image analysis tasks in the FLARE 2025 2D Medical Multimodal Dataset challenge.
The model was fine-tuned on 19 diverse medical imaging datasets from FLARE 2025, including:
Details available at: https://huggingface.co/datasets/FLARE-MedFM/FLARE-Task5-MLLM-2D
# LoRA Configuration
lora_r: 16\nlora_alpha: 32
lora_dropout: 0.1
target_modules: ['gate_proj', 'up_proj', 'o_proj', 'down_proj', 'v_proj', 'q_proj', 'k_proj']
task_type: CAUSAL_LM
bias: none
This model has been evaluated across multiple medical imaging tasks using FLARE 2025 evaluation metrics:
Classification Tasks (Disease Diagnosis):
Multi-label Classification (Multi-pathology):
Detection Tasks (Anatomical/Pathological):
Instance Detection (Identity-Aware Detection):
Counting Tasks (Cell/Structure Counting):
Regression Tasks (Medical Measurements):
Report Generation (Medical Reports):
pip install transformers torch peft accelerate bitsandbytes
import torch
from transformers import AutoTokenizer, AutoProcessor, AutoModelForImageTextToText
from peft import PeftModel
from PIL import Image
# Load the fine-tuned model
base_model_name = "google/medgemma-4b-it"
adapter_model_name = "leoyinn/flare25-medgemma"
# Load tokenizer and processor
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
processor = AutoProcessor.from_pretrained(base_model_name, trust_remote_code=True)
# Load base model
base_model = AutoModelForImageTextToText.from_pretrained(
base_model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
attn_implementation="eager"
)
# Load the fine-tuned adapter
model = PeftModel.from_pretrained(base_model, adapter_model_name)
# Prepare input with MedGemma chat format
image = Image.open("medical_image.jpg").convert("RGB")
image = image.resize((448, 448)) # MedGemma standard size
# Create proper message format
messages = [
{
"role": "system",
"content": [{
"type": "text",
"text": "You are an expert medical AI assistant specialized in analyzing medical images and providing accurate diagnostic insights."
}]
},
{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": "Describe the medical findings in this image and provide a diagnostic assessment."}
]
}
]
# Apply chat template
full_text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
# Process and generate
inputs = processor(
images=[image],
text=full_text,
return_tensors="pt",
padding=True,
truncation=False
).to(model.device, dtype=torch.bfloat16)
# Generate medical response
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=300,
do_sample=False, # Deterministic for medical applications
use_cache=True,
cache_implementation="dynamic"
)
# Decode response
input_len = inputs["input_ids"].shape[-1]
response = processor.decode(outputs[0][input_len:], skip_special_tokens=True)
print(response)
If you use this model in your research, please cite:
@misc{medgemma-flare2025,
title={MedGemma Fine-tuned for FLARE 2025 Medical Image Analysis},
author={Shuolin Yin},
year={2025},
publisher={Hugging Face},
url={https://huggingface.co/leoyinn/flare25-medgemma}
}
@misc{medgemma-base,
title={MedGemma: Medical Gemma Models for Healthcare},
author={Google Research},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/google/medgemma-4b-it}
}
@misc{flare2025,
title={FLARE 2025: A Multi-Modal Foundation Model Challenge for Medical AI},
year={2025},
url={https://huggingface.co/datasets/FLARE-MedFM/FLARE-Task5-MLLM-2D}
}
For questions or issues, please open an issue in the model repository or contact the authors.
Disclaimer: This model is for research and educational purposes only. Always consult qualified medical professionals for clinical decisions.