Views
No views yet
q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj1from transformers import AutoProcessor, AutoModelForVision2Seq
2from PIL import Image
3import torch
4
5# Load model and processor
6model_name = "erjui/Lingshu-7b-srrg-findings"
7model = AutoModelForVision2Seq.from_pretrained(
8 model_name,
9 trust_remote_code=True,
10 torch_dtype=torch.bfloat16,
11 device_map="auto"
12)
13processor = AutoProcessor.from_pretrained("lingshu-medical-mllm/Lingshu-7B", trust_remote_code=True)
14
15# Load chest X-ray image (single image for SRRG)
16image = Image.open("chest_xray.jpg")
17
18# Prepare input
19messages = [
20 {
21 "role": "system",
22 "content": [{"type": "text", "text": "You are an expert radiologist."}]
23 },
24 {
25 "role": "user",
26 "content": [
27 {"type": "text", "text": "Analyze the chest X-ray images and write the FINDINGS section of a radiology report. Use standard medical terminology and organize findings by anatomical regions."},
28 {"type": "image"}
29 ]
30 }
31]
32
33# Process and generate (max_images_per_sample: 1)
34inputs = processor(images=image, text=messages, return_tensors="pt").to(model.device)
35outputs = model.generate(**inputs, max_new_tokens=512)
36generated_text = processor.decode(outputs[0], skip_special_tokens=True)
37
38print(generated_text)FINDINGS:
Lungs and Airways:
- No pleural effusion or pneumothorax detected
- Bibasilar atelectasis present
Cardiovascular:
- Mild left ventricular enlargement
Musculoskeletal and Chest Wall:
- Bilateral rib fractures noted1@article{kang2025automated,
2 title={Automated Structured Radiology Report Generation with Rich Clinical Context},
3 author={Kang, Seongjae and Lee, Dong Bok and Jung, Juho and Kim, Dongseop and Kim, Won Hwa and Joo, Sunghoon},
4 journal={arXiv preprint arXiv:2510.00428},
5 year={2025}
6}1@article{xu2025lingshu,
2 title={Lingshu: A Generalist Foundation Model for Unified Multimodal Medical Understanding and Reasoning},
3 author={Xu, Weiwen and Chan, Hou Pong and Li, Long and Aljunied, Mahani and Yuan, Ruifeng and Wang, Jianyu and Xiao, Chenghao and Chen, Guizhen and Liu, Chaoqun and Li, Zhaodonghui and others},
4 journal={arXiv preprint arXiv:2506.07044},
5 year={2025}
6}