模型:
ClipMD是基于OpenAI的CLIP模型的医学图像文本匹配模型,具有滑动窗口文本编码器。
模型使用ViT-B/32 Transformer架构作为图像编码器,并使用掩码滑动窗口自注意力Transformer作为文本编码器。这些编码器通过对比损失进行训练,以最大化(图像,文本)对的相似性。
该模型在 ROCO dataset 上进行了微调。
from PIL import Image
from transformers import AutoProcessor,AutoModel
model = AutoModel.from_pretrained("Idan0405/ClipMD",trust_remote_code=True)
processor = AutoProcessor.from_pretrained("Idan0405/ClipMD")
image = Image.open("your image path")
inputs = processor(text=["chest x-ray", "head MRI"], images=image, return_tensors="pt", padding=True)
outputs = model(**inputs)
logits_per_image = outputs[0] # this is the image-text similarity score
probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities