Skip to content

Commit b1b79ff

Browse files
committed
fixed runtime issues in isolated inference mode
1 parent d9dce4e commit b1b79ff

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/stamp/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _run_cli(args: argparse.Namespace) -> None:
8686
tile_size_um=config.preprocessing.tile_size_um,
8787
tile_size_px=config.preprocessing.tile_size_px,
8888
extractor=config.preprocessing.extractor,
89+
tile_extractor=config.preprocessing.tile_extractor,
8990
max_workers=config.preprocessing.max_workers,
9091
device=config.preprocessing.device,
9192
default_slide_mpp=config.preprocessing.default_slide_mpp,

src/stamp/preprocessing/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def extract_(
122122
cache_dir: Path | None,
123123
cache_tiles_ext: ImageExtension,
124124
extractor: ExtractorName | Extractor,
125+
tile_extractor: ExtractorName,
125126
tile_size_px: TilePixels,
126127
tile_size_um: Microns,
127128
max_workers: int,
@@ -222,6 +223,11 @@ def extract_(
222223

223224
extractor = plip()
224225

226+
case ExtractorName.TICON:
227+
from stamp.preprocessing.extractor.ticon import ticon
228+
229+
extractor = ticon(tile_extractor=tile_extractor)
230+
225231
case ExtractorName.EMPTY:
226232
from stamp.preprocessing.extractor.empty import empty
227233

@@ -238,7 +244,8 @@ def extract_(
238244
code_hash = get_processing_code_hash(Path(__file__))[:8]
239245

240246
extractor_id = extractor.identifier
241-
247+
if extractor_id == ExtractorName.TICON and tile_extractor is not None:
248+
extractor_id = f"{extractor_id}-{tile_extractor}"
242249
_logger.info(f"Using extractor {extractor.identifier}")
243250

244251
if cache_dir:
@@ -330,6 +337,8 @@ def extract_(
330337

331338
h5_fp.attrs["stamp_version"] = stamp.__version__
332339
h5_fp.attrs["extractor"] = str(extractor.identifier)
340+
if tile_extractor is not None:
341+
h5_fp.attrs["tile_extractor"] = str(tile_extractor)
333342
h5_fp.attrs["unit"] = "um"
334343
h5_fp.attrs["tile_size_um"] = tile_size_um # changed in v2.1.0
335344
h5_fp.attrs["tile_size_px"] = tile_size_px

src/stamp/preprocessing/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class PreprocessingConfig(BaseModel, arbitrary_types_allowed=True):
4545
tile_size_um: Microns = Microns(256.0)
4646
tile_size_px: TilePixels = TilePixels(224)
4747
extractor: ExtractorName
48-
tile_extractor: ExtractorName | None = None
48+
tile_extractor: ExtractorName
4949
max_workers: int = 8
5050
device: str = "cuda" if torch.cuda.is_available() else "cpu"
5151
generate_hash: bool = True

src/stamp/preprocessing/extractor/ticon_iso.py renamed to src/stamp/preprocessing/extractor/ticon.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class TICON(nn.Module):
146146

147147
def __init__(
148148
self,
149-
tile_extractor: ExtractorName = ExtractorName.H_OPTIMUS_1,
149+
tile_extractor: ExtractorName,
150150
device: str = "cuda",
151151
):
152152
super().__init__()
@@ -221,13 +221,9 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
221221
return out.squeeze(1)
222222

223223

224-
def ticon_iso(
225-
tile_extractor: ExtractorName = ExtractorName.H_OPTIMUS_1,
226-
device: str = "cuda",
227-
) -> Extractor[TICON]:
224+
def ticon(tile_extractor: ExtractorName) -> Extractor[TICON]:
228225
"""Create TICON Isolated Mode extractor."""
229-
model = TICON(tile_extractor=tile_extractor, device=device)
230-
226+
model = TICON(tile_extractor=tile_extractor)
231227
return Extractor(
232228
model=model,
233229
transform=model.get_transform(),

0 commit comments

Comments
 (0)