Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,50 @@
|
|
1 |
-
---
|
2 |
-
license: cc-by-2.0
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-2.0
|
3 |
+
---
|
4 |
+
## Usage of PathGen-CLIP
|
5 |
+
|
6 |
+
```
|
7 |
+
pip install open_clip_torch
|
8 |
+
```
|
9 |
+
|
10 |
+
```python
|
11 |
+
import torch
|
12 |
+
from PIL import Image
|
13 |
+
import open_clip
|
14 |
+
|
15 |
+
model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16', pretrained='path/pathgen-clip.pt')
|
16 |
+
model.eval() # model in train mode by default, impacts some models with BatchNorm or stochastic depth active
|
17 |
+
tokenizer = open_clip.get_tokenizer('ViT-B-32')
|
18 |
+
|
19 |
+
image = preprocess(Image.open("example.png")).unsqueeze(0)
|
20 |
+
text = tokenizer(["An H&E image of tumor patch", "An H&E image of normal patch"])
|
21 |
+
|
22 |
+
with torch.no_grad(), torch.cuda.amp.autocast():
|
23 |
+
image_features = model.encode_image(image)
|
24 |
+
text_features = model.encode_text(text)
|
25 |
+
image_features /= image_features.norm(dim=-1, keepdim=True)
|
26 |
+
text_features /= text_features.norm(dim=-1, keepdim=True)
|
27 |
+
|
28 |
+
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
29 |
+
|
30 |
+
print("Label probs:", text_probs)
|
31 |
+
```
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
## Cite
|
38 |
+
|
39 |
+
```
|
40 |
+
@misc{sun2024pathgen16m16millionpathology,
|
41 |
+
title={PathGen-1.6M: 1.6 Million Pathology Image-text Pairs Generation through Multi-agent Collaboration},
|
42 |
+
author={Yuxuan Sun and Yunlong Zhang and Yixuan Si and Chenglu Zhu and Zhongyi Shui and Kai Zhang and Jingxiong Li and Xingheng Lyu and Tao Lin and Lin Yang},
|
43 |
+
year={2024},
|
44 |
+
eprint={2407.00203},
|
45 |
+
archivePrefix={arXiv},
|
46 |
+
primaryClass={cs.CV},
|
47 |
+
url={https://arxiv.org/abs/2407.00203},
|
48 |
+
}
|
49 |
+
```
|
50 |
+
|