• Stars
    star
    409
  • Rank 105,109 (Top 3 %)
  • Language
    Python
  • Created over 2 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

EMNLP'22 | MedCLIP: Contrastive Learning from Unpaired Medical Images and Texts

MedCLIP

PyPI version Downloads GitHub Repo stars GitHub Repo forks

Wang, Zifeng and Wu, Zhenbang and Agarwal, Dinesh and Sun, Jimeng. (2022). MedCLIP: Contrastive Learning from Unpaired Medical Images and Texts. EMNLP'22.

Paper PDF

Download MedCLIP

Before download MedCLIP, you need to find feasible torch version (with GPU) on https://pytorch.org/get-started/locally/.

Then, download MedCLIP by

pip install git+https://github.com/RyanWangZf/MedCLIP.git

# or

pip install medclip

Three lines to get pretrained MedCLIP models

from medclip import MedCLIPModel, MedCLIPVisionModelViT, MedCLIPVisionModel

# load MedCLIP-ResNet50
model = MedCLIPModel(vision_cls=MedCLIPVisionModel)
model.from_pretrained()

# load MedCLIP-ViT
model = MedCLIPModel(vision_cls=MedCLIPVisionModelViT)
model.from_pretrained()

As simple as using CLIP

from medclip import MedCLIPModel, MedCLIPVisionModelViT
from medclip import MedCLIPProcessor
from PIL import Image

# prepare for the demo image and texts
processor = MedCLIPProcessor()
image = Image.open('./example_data/view1_frontal.jpg')
inputs = processor(
    text=["lungs remain severely hyperinflated with upper lobe emphysema", 
        "opacity left costophrenic angle is new since prior exam ___ represent some loculated fluid cavitation unlikely"], 
    images=image, 
    return_tensors="pt", 
    padding=True
    )

# pass to MedCLIP model
model = MedCLIPModel(vision_cls=MedCLIPVisionModelViT)
model.from_pretrained()
model.cuda()
outputs = model(**inputs)
print(outputs.keys())
# dict_keys(['img_embeds', 'text_embeds', 'logits', 'loss_value', 'logits_per_text'])

MedCLIP for Prompt-based Classification

from medclip import MedCLIPModel, MedCLIPVisionModelViT
from medclip import MedCLIPProcessor
from medclip import PromptClassifier

processor = MedCLIPProcessor()
model = MedCLIPModel(vision_cls=MedCLIPVisionModelViT)
model.from_pretrained()
clf = PromptClassifier(model, ensemble=True)
clf.cuda()

# prepare input image
from PIL import Image
image = Image.open('./example_data/view1_frontal.jpg')
inputs = processor(images=image, return_tensors="pt")

# prepare input prompt texts
from medclip.prompts import generate_chexpert_class_prompts, process_class_prompts
cls_prompts = process_class_prompts(generate_chexpert_class_prompts(n=10))
inputs['prompt_inputs'] = cls_prompts

# make classification
output = clf(**inputs)
print(output)
# {'logits': tensor([[0.5154, 0.4119, 0.2831, 0.2441, 0.4588]], device='cuda:0',
#       grad_fn=<StackBackward0>), 'class_names': ['Atelectasis', 'Cardiomegaly', 'Consolidation', 'Edema', 'Pleural Effusion']}

How to Get Sentence-level Semantic Labels

You can refer to https://github.com/stanfordmlgroup/chexpert-labeler where wonderful information extraction tools are offered!

More Repositories

1

transtab

NeurIPS'22 | TransTab: Learning Transferable Tabular Transformers Across Tables
Python
174
star
2

PyTrial

PyTrial: A Comprehensive Platform for Artificial Intelligence for Drug Development
Python
75
star
3

Influence_Subsampling

Official Implementation of Unweighted Data Subsampling via Influence Function - AAAI 2020
Python
66
star
4

BioBridge

ICLR'24 | BioBridge: Bridging Biomedical Foundation Models via Knowledge Graphs
Jupyter Notebook
54
star
5

Hurst-exponent-R-S-analysis-

Calculates the Hurst exponent of a time series based on Rescaled range (R/S) analysis.
Python
48
star
6

PAC-Bayes-IB

Official repo for PAC-Bayes Information Bottleneck. ICLR 2022.
Jupyter Notebook
44
star
7

SurvTRACE

SurvTRACE: Transformers for Survival Analysis with Competing Events
Python
43
star
8

CVIB-Rec

Official Implementation of Information Theoretic Counterfactual Learning from Missing Not At Random Feedback. NeurIPS 2020.
Python
26
star
9

PromptEHR

EMNLP'22 | PromptEHR: Conditional Electronic Healthcare Records Generation with Prompt Learning
Python
23
star
10

Trial2Vec

Findings of EMNLP'22 | Trial2Vec: Zero-Shot Clinical Trial Document Similarity Search using Self-Supervision
Python
19
star
11

MediTab

The code for the paper "MediTab: Scaling Medical Tabular Data Predictors via Data Consolidation, Enrichment, and Refinement"
Jupyter Notebook
17
star
12

SDSIT

Seminar in Data Science and Information Technology (SDSIT) given by Prof. Laurent El Ghaoui, in Summer, 2020.
9
star
13

StockPricePrediction

A demo of stockprice prediction & arbitrage trading.
Python
7
star
14

HGNN_EHR

Python
5
star
15

Uncertainty-Curriculum-Learning

Official Implementation of Uncertainty-guided Curriculum Learning via Infinitesimal Jackknife.
Jupyter Notebook
4
star
16

CUDA_Tutorial

My CUDA C practices while learning the CUDA C Programming Introduction.
Cuda
3
star
17

construction-site-segmentation

An open dataset for semantic segmentation on construction site, released by the paper: "Deep Semantic Segmentation for Visual Understanding on Construction Sites".
Python
3
star
18

B.S._Graduate_Project

My B.E. graduate project codes.
Python
2
star
19

tf-FFM

Tensorflow based field-aware factorization machine, FFM.
Python
2
star
20

Face_Recognition

A demo on face detection, classification and verification via tensorflow.
Python
1
star
21

tf-deepFM

A deep factorization machine (deepFM) implemented via Tensorflow.
Python
1
star
22

QuantStrategy

Several tools & backtest samples being implemented in Financial Engineering.
Python
1
star
23

ILSVRC2015_VID_operation

How to use ILSVRC2015 video data for object tracking train and test.
Python
1
star
24

My_Leetcode_Solution

Leetcode Practices.
Python
1
star
25

Quant_Investment_Course

Introduction to the Statistical Arbitrage investment.
Python
1
star
26

Learning_from_data

The homework of the course Learning From Data taught by Prof.HUANG in Tsinghua-Berkeley Shenzhen Institute(TBSI).
Python
1
star