🚀 LLaVA-Med v1.5 Mistral用于胸部X光分析
本项目是一个基于多模态基础模型的优化方案,专门针对胸部X光图像进行分析,并利用Kaggle上的“胸部X光图像(肺炎)数据集”来检测肺炎。它能为肺炎诊断提供详细且可解释的输出,助力医疗诊断工作。
🚀 快速开始
本模型是基于 LLaVA-Med v1.5 Mistral-7B 微调的多模态基础模型,可用于分析胸部X光图像并检测肺炎。
项目页面:SelfSynthX
论文链接:使用自合成数据增强多模态基础模型的认知和可解释性
✨ 主要特性
- 基础模型:LLaVA-Med v1.5 Mistral-7B
- 数据集:胸部X光图像(肺炎)
- 创新点:
- 自合成数据:通过生成人类可理解的诊断见解,增强了模型的可解释性。
- 特定领域微调:在医学影像上进行优化,以实现准确的肺炎分类。
- 迭代训练:利用拒绝采样来提高诊断准确性和解释质量。
- 预期用途:辅助从胸部X光图像中进行肺炎诊断,并提供详细且可解释的输出。
📦 安装指南
使用此模型前,请确保你已经安装了必要的库,如requests
、Pillow
、torch
和transformers
。你可以使用以下命令进行安装:
pip install requests pillow torch transformers
💻 使用示例
基础用法
import requests
from PIL import Image
import torch
from transformers import AutoProcessor, LlavaForConditionalGeneration
model_id = "YuchengShi/llava-med-v1.5-mistral-7b-chest-xray"
model = LlavaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=torch.float16,
low_cpu_mem_usage=True,
).to("cuda")
processor = AutoProcessor.from_pretrained(model_id)
conversation = [
{
"role": "user",
"content": [
{"type": "text", "text": "Can you analyze this chest X-ray?"},
{"type": "image"},
],
},
]
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
image_file = "chest-xray/test1.png"
raw_image = Image.open(requests.get(image_file, stream=True).raw)
inputs = processor(images=raw_image, text=prompt, return_tensors='pt').to("cuda", torch.float16)
output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
print(processor.decode(output[0][2:], skip_special_tokens=True))
🔧 技术细节
- 训练:使用LoRA在胸部X光图像(肺炎数据集)上进行微调,并采用迭代拒绝采样。
- 评估:实现了稳健的肺炎分类,并提供可解释的诊断说明。
📄 许可证
本项目采用MIT许可证。
📚 详细文档
引用信息
如果你使用了此模型,请引用以下文献:
@inproceedings{
shi2025enhancing,
title={Enhancing Cognition and Explainability of Multimodal Foundation Models with Self-Synthesized Data},
author={Yucheng Shi and Quanzheng Li and Jin Sun and Xiang Li and Ninghao Liu},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025},
url={https://openreview.net/forum?id=lHbLpwbEyt}
}