Instructions to use umakantcurateai/medgemma-kvasir-finetune-umak with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use umakantcurateai/medgemma-kvasir-finetune-umak with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="umakantcurateai/medgemma-kvasir-finetune-umak") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("umakantcurateai/medgemma-kvasir-finetune-umak", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use umakantcurateai/medgemma-kvasir-finetune-umak with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "umakantcurateai/medgemma-kvasir-finetune-umak" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "umakantcurateai/medgemma-kvasir-finetune-umak", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/umakantcurateai/medgemma-kvasir-finetune-umak
- SGLang
How to use umakantcurateai/medgemma-kvasir-finetune-umak with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "umakantcurateai/medgemma-kvasir-finetune-umak" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "umakantcurateai/medgemma-kvasir-finetune-umak", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "umakantcurateai/medgemma-kvasir-finetune-umak" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "umakantcurateai/medgemma-kvasir-finetune-umak", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use umakantcurateai/medgemma-kvasir-finetune-umak with Docker Model Runner:
docker model run hf.co/umakantcurateai/medgemma-kvasir-finetune-umak
MedGemma-4B Kvasir Fine-Tune
This model is a fine-tuned version of google/medgemma-4b-it trained specifically to classify gastrointestinal (GI) tract findings and anatomical landmarks from endoscopic imagery.
Developed by Umakant Biswal, this model utilizes Parameter-Efficient Fine-Tuning (LoRA) to achieve high accuracy in medical image analysis.
Model Performance
The model was evaluated on a 100-image holdout validation subset of the Kvasir dataset, demonstrating a massive +80.00% boost in accuracy compared to the base model on this specific task:
- Accuracy: 87.00% (Up from 7.00% Base)
- F1 Score: 0.8718 (Up from 0.1001 Base)
Supported Classes
The model is trained to return one of the following 8 standardized classes:
A: dyed-lifted-polypsB: dyed-resection-marginsC: esophagitisD: normal-cecumE: normal-pylorusF: normal-z-lineG: polypsH: ulcerative-colitis
Quick Start
The model requires the images to be passed directly inside the chat template's content array. Here is how to load and run inference:
import torch
from transformers import pipeline
from PIL import Image
import requests
# 1. Load the Model
pipe = pipeline(
"image-text-to-text",
model="umakantcurateai/medgemma-kvasir-finetune-umak",
torch_dtype=torch.bfloat16,
device_map="auto"
)
pipe.model.generation_config.do_sample = False
pipe.processor.tokenizer.padding_side = "left"
# 2. Load an Endoscopy Image
url = "[https://example.com/path_to_endoscopy_image.jpg](https://example.com/path_to_endoscopy_image.jpg)" # Replace with your image
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
# 3. Define the Prompt & Multiple Choice Options
PROMPT = """What is the most likely endoscopic finding or anatomical landmark shown in this image?
A: dyed-lifted-polyps
B: dyed-resection-margins
C: esophagitis
D: normal-cecum
E: normal-pylorus
F: normal-z-line
G: polyps
H: ulcerative-colitis"""
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "text", "text": PROMPT}
]
}
]
# 4. Generate Classification
output = pipe(messages, max_new_tokens=20, return_full_text=False)
print(f"Predicted Class: {output[0]['generated_text']}")