reduce memory requirements
Browse files- .gitattributes +1 -0
- README.md +2 -2
- exaonepath.py +9 -3
- samples/sample.svs +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.svs filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -21,7 +21,7 @@ Using only 35k WSIs for training, EXAONE Path 2.0 achieves state-of-the-art aver
|
|
| 21 |
Load EXAONE Path 2.0 and extract features.
|
| 22 |
|
| 23 |
### 1. Prerequisites ###
|
| 24 |
-
- NVIDIA GPU with
|
| 25 |
- Python 3.12+
|
| 26 |
|
| 27 |
Note: This implementation requires NVIDIA GPU and drivers. The provided environment setup specifically uses CUDA-enabled PyTorch, making NVIDIA GPU mandatory for running the model.
|
|
@@ -40,7 +40,7 @@ from exaonepath import EXAONEPathV20
|
|
| 40 |
hf_token = "YOUR_HUGGING_FACE_ACCESS_TOKEN"
|
| 41 |
model = EXAONEPathV20.from_pretrained("LGAI-EXAONE/EXAONE-Path-2.0", use_auth_token=hf_token)
|
| 42 |
|
| 43 |
-
svs_path = "
|
| 44 |
patch_features = model(svs_path)[0]
|
| 45 |
```
|
| 46 |
|
|
|
|
| 21 |
Load EXAONE Path 2.0 and extract features.
|
| 22 |
|
| 23 |
### 1. Prerequisites ###
|
| 24 |
+
- NVIDIA GPU with 12GB+ VRAM
|
| 25 |
- Python 3.12+
|
| 26 |
|
| 27 |
Note: This implementation requires NVIDIA GPU and drivers. The provided environment setup specifically uses CUDA-enabled PyTorch, making NVIDIA GPU mandatory for running the model.
|
|
|
|
| 40 |
hf_token = "YOUR_HUGGING_FACE_ACCESS_TOKEN"
|
| 41 |
model = EXAONEPathV20.from_pretrained("LGAI-EXAONE/EXAONE-Path-2.0", use_auth_token=hf_token)
|
| 42 |
|
| 43 |
+
svs_path = "samples/sample.svs"
|
| 44 |
patch_features = model(svs_path)[0]
|
| 45 |
```
|
| 46 |
|
exaonepath.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import math
|
| 2 |
import typing as t
|
| 3 |
from functools import partial
|
|
|
|
| 4 |
|
| 5 |
import torch
|
| 6 |
import torch.nn as nn
|
|
@@ -17,7 +18,7 @@ from utils.tensor_utils import (
|
|
| 17 |
scale_and_normalize,
|
| 18 |
tile,
|
| 19 |
)
|
| 20 |
-
from utils.wsi_utils import load_slide_img,
|
| 21 |
|
| 22 |
if t.TYPE_CHECKING:
|
| 23 |
from _typeshed import StrPath
|
|
@@ -90,9 +91,10 @@ class EXAONEPathV20(nn.Module, PyTorchModelHubMixin):
|
|
| 90 |
small_tile_size_with_target_mpp=self.small_tile_size,
|
| 91 |
),
|
| 92 |
device=self.device,
|
| 93 |
-
out_device=
|
| 94 |
dtype=torch.bfloat16,
|
| 95 |
)
|
|
|
|
| 96 |
act1_formatted = format_first_stg_act_as_second_stg_inp(
|
| 97 |
act1,
|
| 98 |
height=height,
|
|
@@ -112,6 +114,8 @@ class EXAONEPathV20(nn.Module, PyTorchModelHubMixin):
|
|
| 112 |
return act1[is_tile_valid], act2, act3
|
| 113 |
|
| 114 |
def _load_wsi(self, svs_path: "StrPath", target_mpp: float):
|
|
|
|
|
|
|
| 115 |
# Load WSI tile
|
| 116 |
with CuImage(str(svs_path)) as wsi_obj:
|
| 117 |
try:
|
|
@@ -124,7 +128,9 @@ class EXAONEPathV20(nn.Module, PyTorchModelHubMixin):
|
|
| 124 |
|
| 125 |
img = load_slide_img(wsi_obj)
|
| 126 |
height, width = img.shape[:2]
|
| 127 |
-
mask_tensor = torch.from_numpy(
|
|
|
|
|
|
|
| 128 |
mask_tensor = TF.resize(mask_tensor.unsqueeze(0), [height, width]).squeeze(
|
| 129 |
0
|
| 130 |
)
|
|
|
|
| 1 |
import math
|
| 2 |
import typing as t
|
| 3 |
from functools import partial
|
| 4 |
+
from pathlib import Path
|
| 5 |
|
| 6 |
import torch
|
| 7 |
import torch.nn as nn
|
|
|
|
| 18 |
scale_and_normalize,
|
| 19 |
tile,
|
| 20 |
)
|
| 21 |
+
from utils.wsi_utils import load_slide_img, segment_tissue
|
| 22 |
|
| 23 |
if t.TYPE_CHECKING:
|
| 24 |
from _typeshed import StrPath
|
|
|
|
| 91 |
small_tile_size_with_target_mpp=self.small_tile_size,
|
| 92 |
),
|
| 93 |
device=self.device,
|
| 94 |
+
out_device="cpu",
|
| 95 |
dtype=torch.bfloat16,
|
| 96 |
)
|
| 97 |
+
act1 = act1.to(self.device)
|
| 98 |
act1_formatted = format_first_stg_act_as_second_stg_inp(
|
| 99 |
act1,
|
| 100 |
height=height,
|
|
|
|
| 114 |
return act1[is_tile_valid], act2, act3
|
| 115 |
|
| 116 |
def _load_wsi(self, svs_path: "StrPath", target_mpp: float):
|
| 117 |
+
svs_path = str(svs_path)
|
| 118 |
+
|
| 119 |
# Load WSI tile
|
| 120 |
with CuImage(str(svs_path)) as wsi_obj:
|
| 121 |
try:
|
|
|
|
| 128 |
|
| 129 |
img = load_slide_img(wsi_obj)
|
| 130 |
height, width = img.shape[:2]
|
| 131 |
+
mask_tensor = torch.from_numpy(
|
| 132 |
+
segment_tissue(Path(svs_path), seg_level=-1)[0]
|
| 133 |
+
)
|
| 134 |
mask_tensor = TF.resize(mask_tensor.unsqueeze(0), [height, width]).squeeze(
|
| 135 |
0
|
| 136 |
)
|
samples/sample.svs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a294dc33a7489e09262b4133b6802b535576c44e3386cf2b9eb896a74702191b
|
| 3 |
+
size 532458405
|