Skip to content

Commit e4534d1

Browse files
shaneahmedpre-commit-ci[bot]John-Pmostafajahanifarvqdang
authored
NEW: Add SCCNN Cell Detection Architecture (#434)
- Add SCCNN architecture. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: John Pocock <[email protected]> Co-authored-by: Mostafa Jahanifar <[email protected]> Co-authored-by: Dang Vu <[email protected]>
1 parent fb7f884 commit e4534d1

File tree

8 files changed

+460
-4
lines changed

8 files changed

+460
-4
lines changed

docs/usage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Neural Network Architectures
111111
- :obj:`HoVerNet <tiatoolbox.models.architecture.hovernet.HoVerNet>`
112112
- :obj:`HoVerNet+ <tiatoolbox.models.architecture.hovernetplus.HoVerNetPlus>`
113113
- :obj:`MicroNet <tiatoolbox.models.architecture.micronet.MicroNet>`
114+
- :obj:`SCCNN <tiatoolbox.models.architecture.sccnn.SCCNN>`
114115

115116
Pipelines:
116117
- :obj:`IDARS <tiatoolbox.models.architecture.idars>`

tests/models/test_arch_micronet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# skipcq: PTC-W6004
2-
"""Unit test package for HoVerNet."""
2+
"""Unit test package for MicroNet."""
33

44
import pathlib
55

tests/models/test_arch_sccnn.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Unit test package for SCCNN."""
2+
import numpy as np
3+
import torch
4+
5+
from tiatoolbox import utils
6+
from tiatoolbox.models.architecture import fetch_pretrained_weights
7+
from tiatoolbox.models.architecture.sccnn import SCCNN
8+
from tiatoolbox.wsicore.wsireader import WSIReader
9+
10+
11+
def _load_sccnn(tmp_path, name):
12+
"""Loads SCCNN model with specified weights."""
13+
model = SCCNN()
14+
fetch_pretrained_weights(name, f"{tmp_path}/weights.pth")
15+
map_location = utils.misc.select_device(utils.env_detection.has_gpu())
16+
pretrained = torch.load(f"{tmp_path}/weights.pth", map_location=map_location)
17+
model.load_state_dict(pretrained)
18+
19+
return model
20+
21+
22+
def test_functionality(remote_sample, tmp_path):
23+
"""Functionality test for SCCNN.
24+
25+
Tests the functionality of SCCNN model for inference at the patch level.
26+
27+
"""
28+
tmp_path = str(tmp_path)
29+
sample_wsi = str(remote_sample("wsi1_2k_2k_svs"))
30+
reader = WSIReader.open(sample_wsi)
31+
32+
# * test fast mode (architecture used in PanNuke paper)
33+
patch = reader.read_bounds(
34+
(30, 30, 61, 61), resolution=0.25, units="mpp", coord_space="resolution"
35+
)
36+
batch = torch.from_numpy(patch)[None]
37+
model = _load_sccnn(tmp_path=tmp_path, name="sccnn-crchisto")
38+
output = model.infer_batch(model, batch, on_gpu=False)
39+
output = model.postproc(output[0])
40+
assert np.all(output == [[8, 7]])
41+
42+
model = _load_sccnn(tmp_path=tmp_path, name="sccnn-conic")
43+
output = model.infer_batch(model, batch, on_gpu=False)
44+
output = model.postproc(output[0])
45+
assert np.all(output == [[7, 8]])

tiatoolbox/data/pretrained_model.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,3 +771,27 @@ micronet-consep:
771771
patch_output_shape: [252, 252]
772772
stride_shape: [150, 150]
773773
save_resolution: {'units': 'mpp', 'resolution': 0.25}
774+
775+
sccnn-crchisto:
776+
url: https://tiatoolbox.dcs.warwick.ac.uk/models/detection/sccnn-crchisto.pth
777+
architecture:
778+
class: sccnn.SCCNN
779+
kwargs:
780+
num_input_channels: 3
781+
out_height: 13
782+
out_width: 13
783+
radius: 12
784+
min_distance: 6
785+
threshold_abs: 0.20
786+
787+
sccnn-conic:
788+
url: https://tiatoolbox.dcs.warwick.ac.uk/models/detection/sccnn-conic.pth
789+
architecture:
790+
class: sccnn.SCCNN
791+
kwargs:
792+
num_input_channels: 3
793+
out_height: 13
794+
out_width: 13
795+
radius: 12
796+
min_distance: 5
797+
threshold_abs: 0.05

tiatoolbox/models/architecture/micronet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ def out_arch_branch(in_ch, num_class=2):
343343

344344

345345
class MicroNet(ModelABC):
346-
"""Initialise MicroNet [1].
346+
"""Initialize MicroNet [1].
347347
348348
The following models have been included in tiatoolbox:
349+
349350
1. `micronet-consep`:
350351
This is trained on `CoNSeP dataset
351352
<https://warwick.ac.uk/fac/cross_fac/tia/data/hovernet/>`_ The

0 commit comments

Comments
 (0)