jianght commited on
Commit
f982020
·
verified ·
1 Parent(s): 9fa9b5e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +53 -46
README.md CHANGED
@@ -1,47 +1,54 @@
1
- ## How to use UniCAS to extract features.
2
-
3
- The code below can be used to run inference; `UniCAS` expects images of size 224x224 that were extracted at 20× magnification.
4
-
5
- ```python
6
- import functools
7
- import timm
8
- import torch
9
- from torchvision import transforms
10
-
11
- params = {
12
- 'patch_size': 16,
13
- 'embed_dim': 1024,
14
- 'depth': 24,
15
- 'num_heads': 16,
16
- 'init_values': 1e-05,
17
- 'mlp_ratio': 2.671875 * 2,
18
- 'mlp_layer': functools.partial(
19
- timm.layers.mlp.GluMlp, gate_last=False
20
- ),
21
- 'act_layer': torch.nn.modules.activation.SiLU,
22
- 'no_embed_class': False,
23
- 'img_size': 224,
24
- 'num_classes': 0,
25
- 'in_chans': 3
26
- }
27
-
28
- model = timm.models.VisionTransformer(**params)
29
- print(model.load_state_dict(torch.load("UniCAS.pth"), strict=False))
30
- model = model.eval().to("cuda")
31
-
32
-
33
- transform = transforms.Compose([
34
- transforms.ToTensor(),
35
- transforms.Normalize(
36
- mean=(0.485, 0.456, 0.406),
37
- std=(0.229, 0.224, 0.225),
38
- ),
39
- ])
40
-
41
- input = torch.rand(3, 224, 224)
42
- input = transforms.ToPILImage()(input)
43
- input = transform(input).unsqueeze(0)
44
- with torch.no_grad():
45
- features = model(input.to("cuda"))
46
- print(features.shape) # torch.Size([1, 1024])
 
 
 
 
 
 
 
47
  ```
 
1
+ ---
2
+ tags:
3
+ - cytology foundation model
4
+ - vision transformer
5
+ - cervical screening
6
+ license: apache-2.0
7
+ ---
8
+ ## How to use UniCAS to extract features.
9
+
10
+ The code below can be used to run inference; `UniCAS` expects images of size 224x224 that were extracted at 20× magnification.
11
+
12
+ ```python
13
+ import functools
14
+ import timm
15
+ import torch
16
+ from torchvision import transforms
17
+
18
+ params = {
19
+ 'patch_size': 16,
20
+ 'embed_dim': 1024,
21
+ 'depth': 24,
22
+ 'num_heads': 16,
23
+ 'init_values': 1e-05,
24
+ 'mlp_ratio': 2.671875 * 2,
25
+ 'mlp_layer': functools.partial(
26
+ timm.layers.mlp.GluMlp, gate_last=False
27
+ ),
28
+ 'act_layer': torch.nn.modules.activation.SiLU,
29
+ 'no_embed_class': False,
30
+ 'img_size': 224,
31
+ 'num_classes': 0,
32
+ 'in_chans': 3
33
+ }
34
+
35
+ model = timm.models.VisionTransformer(**params)
36
+ print(model.load_state_dict(torch.load("UniCAS.pth"), strict=False))
37
+ model = model.eval().to("cuda")
38
+
39
+
40
+ transform = transforms.Compose([
41
+ transforms.ToTensor(),
42
+ transforms.Normalize(
43
+ mean=(0.485, 0.456, 0.406),
44
+ std=(0.229, 0.224, 0.225),
45
+ ),
46
+ ])
47
+
48
+ input = torch.rand(3, 224, 224)
49
+ input = transforms.ToPILImage()(input)
50
+ input = transform(input).unsqueeze(0)
51
+ with torch.no_grad():
52
+ features = model(input.to("cuda"))
53
+ print(features.shape) # torch.Size([1, 1024])
54
  ```