jamessyx commited on
Commit
08adf14
·
verified ·
1 Parent(s): 2c283d1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +40 -3
README.md CHANGED
@@ -1,3 +1,40 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ ---
4
+ # PathGen-CLIP
5
+
6
+ This is the official PathGen-CLIP trained based on **PathGen-1.6M: 1.6 Million Pathology Image-text Pairs Generation through Multi-agent Collaboration**
7
+
8
+ ## Usage of Trained PathGen-CLIP series model
9
+
10
+ The trained PathGen-CLIP can be downloaded via this [**PathGen-CLIP**](https://pub-7a38cc906afa44a4a01533c288d0b1af.r2.dev/pathgenclip.pt) and the PathGen-CLIP-L via this [**PathGen-CLIP-L**](https://huggingface.co/jamessyx/PathGen-CLIP-L) (We also transform PathGen-CLIP-L to HF version [**PathGenCLIP-vit-large-patch14-hf**](https://huggingface.co/jamessyx/pathgenclip-vit-large-patch14-hf) to facilitate the integration into LLM).
11
+
12
+ ```
13
+ pip install open_clip_torch
14
+ ```
15
+
16
+ ```python
17
+ import torch
18
+ from PIL import Image
19
+ import open_clip
20
+
21
+ model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16', pretrained='path/pathgen-clip.pt') // PathGen-CLIP
22
+ # model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16', pretrained='path/pathgen-clip-l.pt') // PathGen-CLIP-L
23
+ model.eval() # model in train mode by default, impacts some models with BatchNorm or stochastic depth active
24
+ tokenizer = open_clip.get_tokenizer('ViT-B-16')
25
+
26
+ image = preprocess(Image.open("example.png")).unsqueeze(0)
27
+ text = tokenizer(["An H&E image of tumor patch", "An H&E image of normal patch"])
28
+
29
+ with torch.no_grad(), torch.cuda.amp.autocast():
30
+ image_features = model.encode_image(image)
31
+ text_features = model.encode_text(text)
32
+ image_features /= image_features.norm(dim=-1, keepdim=True)
33
+ text_features /= text_features.norm(dim=-1, keepdim=True)
34
+
35
+ text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
36
+
37
+ print("Label probs:", text_probs)
38
+ ```
39
+
40
+