Skip to content

Commit 90e84e5

Browse files
authored
DEV: Add Auxiliary Functionality For SlideGraph (#208)
Migrate existing .py in #180 to another branch. Included functionalities are: - Generic graph plotting onto canvas - Plat Scaler for calibrating probabilities - Pin scikit-image to avoid errors due to changes in the updated version. - [x] Add functionalities - [x] Add tests Co-authored-by: @vqdang
1 parent d98d04b commit 90e84e5

File tree

15 files changed

+329
-32
lines changed

15 files changed

+329
-32
lines changed

requirements.conda.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- jupyterlab
1616
- matplotlib
1717
- numpy
18-
- opencv>=4.0
18+
- opencv==4.5.4.60
1919
- openjpeg>=2.3.0
2020
- openslide
2121
- pandas
@@ -27,7 +27,7 @@ dependencies:
2727
- pytorch
2828
- pyyaml>=5.1
2929
- requests
30-
- scikit-image
30+
- scikit-image==0.18.3
3131
- scikit-learn>=0.23.2
3232
- shapely
3333
- tifffile

requirements.dev.conda.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
- jupyterlab
1919
- matplotlib
2020
- numpy
21-
- opencv>=4.0
21+
- opencv==4.5.4.60
2222
- openjpeg>=2.3.0
2323
- openslide
2424
- pandas
@@ -34,7 +34,7 @@ dependencies:
3434
- pyyaml>=5.1
3535
- recommonmark
3636
- requests
37-
- scikit-image
37+
- scikit-image==0.18.3
3838
- scikit-learn>=0.23.2
3939
- shapely
4040
- tifffile

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ imagecodecs
66
jupyterlab
77
matplotlib
88
numpy
9-
opencv-python>=4.0
9+
opencv-python==4.5.4.60
1010
openslide-python==1.1.2
1111
pandas
1212
pillow
1313
pyyaml>=5.1
1414
requests
15-
scikit-image
15+
scikit-image==0.18.3
1616
scikit-learn>=0.23.2
1717
shapely
1818
sphinx==4.1.2

requirements.win64.conda.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- jupyterlab
1616
- matplotlib
1717
- numpy
18-
- opencv>=4.0
18+
- opencv==4.5.4.60
1919
- openjpeg>=2.3.0
2020
- pandas
2121
- pillow
@@ -25,7 +25,7 @@ dependencies:
2525
- pytorch
2626
- pyyaml>=5.1
2727
- requests
28-
- scikit-image
28+
- scikit-image==0.18.3
2929
- scikit-learn>=0.23.2
3030
- shapely
3131
- tifffile

requirements_dev.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ imagecodecs
1010
jupyterlab
1111
matplotlib
1212
numpy
13-
opencv-python>=4.0
13+
opencv-python==4.5.4.60
1414
openslide-python==1.1.2
1515
pandas
1616
pillow
@@ -22,7 +22,7 @@ pytest==6.2.5
2222
pyyaml>=5.1
2323
recommonmark
2424
requests
25-
scikit-image
25+
scikit-image==0.18.3
2626
scikit-learn>=0.23.2
2727
shapely
2828
sphinx==4.1.2

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
"numpy",
1717
"pillow",
1818
"matplotlib",
19-
"opencv-python>=4.0",
19+
"opencv-python==4.5.4.60",
2020
"openslide-python==1.1.2",
2121
"pyyaml>=5.1",
2222
"pandas",
2323
"glymur",
2424
"scikit-learn>=0.23.2",
25-
"scikit-image>=0.17",
25+
"scikit-image==0.18.3",
2626
"shapely",
2727
"torchvision==0.10.1",
2828
"torch==1.9.1",

tests/test_scale.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Tests for scaling methods."""
2+
3+
import numpy as np
4+
import pytest
5+
6+
from tiatoolbox.tools.scale import PlattScaling
7+
8+
9+
def test_platt_scaler():
10+
"""Test for Platt scaler."""
11+
np.random.seed(5)
12+
sample_size = 1000
13+
logit = np.random.rand(sample_size)
14+
# binary class
15+
label = np.concatenate(
16+
[np.full(int(0.9 * sample_size), -1), np.full(int(0.1 * sample_size), 1)]
17+
)
18+
scaler = PlattScaling(num_iters=1)
19+
scaler._fixer_a = 0.0
20+
scaler._fixer_b = 0.0
21+
_ = scaler.fit_transform(logit * 0.01, label)
22+
23+
scaler = PlattScaling(num_iters=1)
24+
scaler._fixer_a = 0.0
25+
scaler._fixer_b = 1.0
26+
_ = scaler.fit_transform(logit * 0.01, label)
27+
28+
scaler = PlattScaling(num_iters=10)
29+
_ = scaler.fit_transform(logit * 100, label)
30+
31+
label = np.concatenate([np.full(int(sample_size), -1)])
32+
scaler = PlattScaling(num_iters=1)
33+
_ = scaler.fit_transform(logit * 0.01, label)
34+
35+
with pytest.raises(ValueError, match=r".*same shape.*"):
36+
scaler.fit_transform(logit, label[:2])
37+
print(scaler)

tests/test_visualization.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from tiatoolbox.utils.visualization import (
1212
overlay_prediction_contours,
1313
overlay_prediction_mask,
14+
plot_graph,
1415
)
1516
from tiatoolbox.wsicore.wsireader import get_wsireader
1617

@@ -130,3 +131,18 @@ def test_overlay_instance_prediction():
130131
# test crash
131132
with pytest.raises(ValueError, match=r"`.*inst_colours`.*tuple.*"):
132133
overlay_prediction_contours(canvas, inst_dict, inst_colours=inst_colours)
134+
135+
136+
def test_plot_graph():
137+
"""Test plotting graph."""
138+
canvas = np.zeros([10, 10])
139+
nodes = np.array([[1, 1], [2, 2], [2, 5]])
140+
edges = np.array([[0, 1], [1, 2], [2, 0]])
141+
node_colors = np.array([[0, 0, 0]] * 3)
142+
edge_colors = np.array([[1, 1, 1]] * 3)
143+
plot_graph(
144+
canvas,
145+
nodes,
146+
edges,
147+
)
148+
plot_graph(canvas, nodes, edges, node_colors=node_colors, edge_colors=edge_colors)

tiatoolbox/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
WSIPatchDataset,
2929
)
3030
from tiatoolbox.models.engine.semantic_segmentor import (
31+
FeatureExtractor,
3132
IOSegmentorConfig,
3233
SemanticSegmentor,
3334
WSIStreamDataset,

tiatoolbox/models/architecture/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import torch
2929

3030
from tiatoolbox import rcParam
31+
from tiatoolbox.models.architecture.vanilla import CNNExtractor, CNNModel
3132
from tiatoolbox.models.dataset.classification import predefined_preproc_func
3233
from tiatoolbox.utils.misc import download_data
3334

0 commit comments

Comments
 (0)