🚀 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}
}