Views
No views yet
1import requests
2from PIL import Image
3import torch
4from transformers import AutoProcessor, LlavaForConditionalGeneration
5
6model_id = "YuchengShi/LLaVA-v1.5-7B-HAM10000"
7model = LlavaForConditionalGeneration.from_pretrained(
8 model_id,
9 torch_dtype=torch.float16,
10 low_cpu_mem_usage=True,
11).to("cuda")
12processor = AutoProcessor.from_pretrained(model_id)
13
14conversation = [
15 {
16 "role": "user",
17 "content": [
18 {"type": "text", "text": "What type of skin lesion is this?"},
19 {"type": "image"},
20 ],
21 },
22]
23prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
24image_file = "ham10000/test1.png"
25raw_image = Image.open(requests.get(image_file, stream=True).raw)
26inputs = processor(images=raw_image, text=prompt, return_tensors='pt').to("cuda", torch.float16)
27
28output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
29print(processor.decode(output[0][2:], skip_special_tokens=True))1@inproceedings{
2 shi2025enhancing,
3 title={Enhancing Cognition and Explainability of Multimodal Foundation Models with Self-Synthesized Data},
4 author={Yucheng Shi and Quanzheng Li and Jin Sun and Xiang Li and Ninghao Liu},
5 booktitle={The Thirteenth International Conference on Learning Representations},
6 year={2025},
7 url={https://openreview.net/forum?id=lHbLpwbEyt}
8}