Update README.md
Browse files
README.md
CHANGED
|
@@ -1,47 +1,54 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
'
|
| 22 |
-
'
|
| 23 |
-
'
|
| 24 |
-
'
|
| 25 |
-
'
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
```
|