Views
No views yet
| Base model | Qwen/Qwen2.5-VL-7B-Instruct |
| Training data | DnaRnaProteins/cell_seg_labeled |
| Fine-tuning | QLoRA (4-bit, PEFT) via TRL SFTTrainer |
| Evaluation | ROUGE-L on validation split before push |
1import torch
2from PIL import Image
3from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
4from qwen_vl_utils import process_vision_info
5
6model_id = "DnaRnaProteins/qwen2.5-vl-7b-cells-cap"
7processor = AutoProcessor.from_pretrained(model_id)
8model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
9 model_id, torch_dtype=torch.bfloat16, device_map="auto"
10)
11
12image = Image.open("cell_image.png").convert("RGB")
13messages = [{
14 "role": "user",
15 "content": [
16 {"type": "image", "image": image},
17 {"type": "text", "text": (
18 "You are a biomedical imaging expert. Describe what you observe in this "
19 "microscopy image of cells. Include cell morphology, density, any visible "
20 "structures, and any notable features relevant to biomechanics analysis."
21 )},
22 ],
23}]
24
25text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
26image_inputs, _ = process_vision_info(messages)
27inputs = processor(text=[text], images=image_inputs, return_tensors="pt").to(model.device)
28
29with torch.inference_mode():
30 out = model.generate(**inputs, max_new_tokens=256)
31
32caption = processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)1import base64, modal
2
3caption_fn = modal.Function.from_name("biomech-inference-serving", "caption")
4with open("cell_image.png", "rb") as f:
5 b64 = base64.b64encode(f.read()).decode()
6result = caption_fn.remote(b64)
7# {"caption": "The image shows densely packed epithelial cells..."}