【项目实战】通过LLaMaFactory+Qwen2-VL-2B微调一个多模态医疗大模型
前言随着多模态大模型的发展,其不光限于笔墨处理,更能够在图像、视频、音频方面进行识别与理解。医疗范畴中,大夫们往往需要对各种医学图像进行处理,以辅助诊断和治疗。如果将多模态大模型与图像诊断相联合,那么这会极大地提升诊断服从。
项目目标
训练一个医疗多模态大模型,用于图像诊断。
刚好家里老爷子近期略感头疼,去医院做了脑部CT,诊断患有垂体瘤,我将实验使用多模态大模型进行进一步诊断。
实现过程
1. 数据集准备
为了训练模型,需要准备大量的医学图像数据。通过搜索我们找到以下训练数据:
数据名称:MedTrinity-25M
数据所在:https://github.com/UCSC-VLAA/MedTrinity-25M
数据简介:MedTrinity-25M数据集是一个用于医学图像分析和计算机视觉研究的大型数据集。
数据来源:该数据集由加州大学圣克鲁兹分校(UCSC)提供,旨在促进医学图像处理和分析的研究。
数据量:MedTrinity-25M包罗约2500万条医学图像数据,涵盖多种医学成像技术,如CT、MRI和超声等。
数据内容:
该数据集有两份,分别是 25Mdemo 和 25Mfull 。
25Mdemo (约162,000条)数据集内容如下:
https://img-blog.csdnimg.cn/img_convert/4a9267d3cdcd7d1c682c8d9d1fb35e3f.png
25Mfull (约24,800,000条)数据集内容如下:
https://img-blog.csdnimg.cn/img_convert/d4a32e4ea4747de731bf99a16cb77bac.png
2. 数据下载
2.1 安装Hugging Face的Datasets库
pip install datasets
2.2 下载数据集
from datasets import load_dataset
# 加载数据集
ds = load_dataset("UCSC-VLAA/MedTrinity-25M", "25M_demo", cache_dir="cache")
实行结果:
https://img-blog.csdnimg.cn/img_convert/7eb129605f034857ac6bb21dfa8c2728.png
说明:
[*]以上方法是使用HuggingFace的Datasets库下载数据集,下载的路径为当前脚当所在路径下的cache文件夹。
[*]使用HuggingFace下载需要能够访问https://huggingface.co/ 而且在网站上申请数据集读取权限才可以。
[*]如果没有权限访问HuggingFace,可以关注一起AI技术公众号后,回复 “MedTrinity”获取百度网盘下载所在。
2.3 预览数据集
# 查看训练集的前1个样本
print(ds['train'][:1])
运行结果:
{
'image': [<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=512x512 at 0x15DD6D06530>],
'id': ['8031efe0-1b5c-11ef-8929-000066532cad'],
'caption': ['The image is a non-contrasted computed tomography (CT) scan of the brain, showing the cerebral structures without any medical devices present. The region of interest, located centrally and in the middle of the image, exhibits an area of altered density, which is indicative of a brain hemorrhage. This area is distinct from the surrounding brain tissue, suggesting a possible hematoma or bleeding within the brain parenchyma. The location and characteristics of this abnormality may suggest a relationship with the surrounding brain tissue, potentially causing a mass effect or contributing to increased intracranial pressure.'
]
}
使用如下命令对数据集的图片进行可视化查看:
# 可视化image内容
from PIL import Image
import matplotlib.pyplot as plt
image = ds['train']['image']# 获取第一张图像
plt.imshow(image)
plt.axis('off')# 不显示坐标轴
plt.show()
运行结果:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]