🚀 WhyLesionCLIP模型卡👍🏽
WhyLesionCLIP模型能够将皮肤病变图像与文本描述进行对齐,为医学图像研究提供了新的工具,有助于研究人员开展零样本医学图像分类等相关研究。
🚀 快速开始
使用以下代码开始使用该模型:
pip install open_clip_torch
import torch
from PIL import Image
import open_clip
model, _, preprocess = open_clip.create_model_and_transforms("hf-hub:yyupenn/whylesionclip")
model.eval()
tokenizer = open_clip.get_tokenizer("ViT-L-14")
image = preprocess(Image.open("test_skin.jpg")).unsqueeze(0)
text = tokenizer(["dark brown", "bleeding", "irregular shape"])
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("Label probs:", text_probs)
✨ 主要特性
- WhyLesionCLIP可以将皮肤病变图像与文本描述进行对齐。
- 该模型在多个皮肤病变数据集的零样本和线性探测任务中显著优于PubMedCLIP、BioMedCLIP等模型。
📦 安装指南
使用以下命令安装所需库:
pip install open_clip_torch
💻 使用示例
基础用法
import torch
from PIL import Image
import open_clip
model, _, preprocess = open_clip.create_model_and_transforms("hf-hub:yyupenn/whylesionclip")
model.eval()
tokenizer = open_clip.get_tokenizer("ViT-L-14")
image = preprocess(Image.open("test_skin.jpg")).unsqueeze(0)
text = tokenizer(["dark brown", "bleeding", "irregular shape"])
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("Label probs:", text_probs)
📚 详细文档
模型用途
根据原始的 OpenAI CLIP模型卡,此模型是为研究社区提供的研究成果。我们希望该模型能帮助研究人员更好地理解和探索零样本医学图像(皮肤病变)分类,也希望它能用于跨学科研究此类模型的潜在影响。
- 直接使用:WhyLesionCLIP可用于零样本皮肤病变分类,计算皮肤病变图像与文本描述之间的相似度。
- 下游使用:可作为特征提取器用于下游任务,从皮肤病变图像和文本描述中提取特征。
- 超出适用范围的使用:WhyLesionCLIP不应用于临床诊断或治疗,也不应用于任何临床决策。用户(直接用户和下游用户)应了解该模型的风险、偏差和局限性。
训练详情
训练数据
我们使用 ISIC 数据集,并使用GPT - 4V为56,590张图像生成临床报告。我们对这些报告进行预处理,提取医学相关的发现,每个发现用简短的术语描述。总共,我们组装了438K个图像 - 文本对用于训练WhyLesionCLIP。
训练细节
我们使用 OpenCLIP 的训练脚本,并选择 ViT - L/14 作为骨干网络。在4个RTX A6000 GPU上进行10个epoch的训练,批量大小为128,学习率为1e−5。我们根据验证集上的最低对比损失选择检查点。
评估
测试数据
我们在5个皮肤病变分类数据集上进行评估:HAM10000、BCN20000、PAD - UFES - 20、Melanoma 和 UWaterloo。我们报告了上述5个数据集的零样本和线性探测准确率。
基线模型
我们比较了各种CLIP模型,包括 OpenAI - CLIP、OpenCLIP、PubMedCLIP、BioMedCLIP、PMC - CLIP 和 MedCLIP。我们在零样本和线性探测场景下评估这些模型。在零样本中,GPT - 4为每个类别生成提示,我们使用图像与提示之间的余弦相似度的集合作为每个类别的分数。在线性探测中,我们使用CLIP模型作为图像编码器提取特征进行逻辑回归。此外,我们还包括 DenseNet - 121(在预训练数据集上使用交叉熵损失进行微调)作为线性探测的基线。
结果
下图显示了不同模型在五个皮肤病变数据集上的平均零样本和线性探测性能。

📄 许可证
本项目采用MIT许可证。
📚 引用
如果您在工作中使用了此模型,请引用我们的论文:
@article{yang2024textbook,
title={A Textbook Remedy for Domain Shifts: Knowledge Priors for Medical Image Analysis},
author={Yue Yang and Mona Gandhi and Yufei Wang and Yifan Wu and Michael S. Yao and Chris Callison-Burch and James C. Gee and Mark Yatskar},
journal={arXiv preprint arXiv:2405.14839},
year={2024}
}