From 445b7cc38f3137947e8d52a2c5c7944c8dac7873 Mon Sep 17 00:00:00 2001 From: vqdang <24943262+vqdang@users.noreply.github.com> Date: Mon, 20 Dec 2021 16:28:59 +0000 Subject: [PATCH 1/3] [UPD]: change names --- docs/usage.rst | 2 +- examples/full-pipelines/slide-graph.ipynb | 6 +++--- examples/inference-pipelines/slide-graph.ipynb | 8 ++++---- tests/models/test_feature_extractor.py | 6 +++--- tiatoolbox/models/__init__.py | 2 +- tiatoolbox/models/engine/semantic_segmentor.py | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index a283b9a1a..d28cf4b3e 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -99,7 +99,7 @@ Engine - :obj:`Patch Prediction ` - :obj:`Semantic Segmentation ` -- :obj:`Feature Extraction ` +- :obj:`Feature Extraction ` - :obj:`Nucleus Instance Segmnetation ` ---------------------------- diff --git a/examples/full-pipelines/slide-graph.ipynb b/examples/full-pipelines/slide-graph.ipynb index 2d4f1827b..be6435e43 100644 --- a/examples/full-pipelines/slide-graph.ipynb +++ b/examples/full-pipelines/slide-graph.ipynb @@ -532,7 +532,7 @@ "metadata": {}, "outputs": [], "source": [ - "from tiatoolbox.models import FeatureExtractor, IOSegmentorConfig\n", + "from tiatoolbox.models import DeepFeatureExtractor, IOSegmentorConfig\n", "from tiatoolbox.models.architecture import CNNExtractor\n", "\n", "\n", @@ -554,7 +554,7 @@ " save_resolution={\"units\": \"mpp\", \"resolution\": 8.0},\n", " )\n", " model = CNNExtractor(\"resnet50\")\n", - " extractor = FeatureExtractor(\n", + " extractor = DeepFeatureExtractor(\n", " batch_size=16, model=model, num_loader_workers=4)\n", " # Injecting customized preprocessing functions,\n", " # check the document or sample code below for API.\n", @@ -603,7 +603,7 @@ "and count the nuclei of each type in each patch.\n", "We encapsulate this process in the function `get_composition_features`.\n", "\n", - "Unlike the `FeatureExtractor` above, the `NucleusInstanceSegmentor` engine\n", + "Unlike the `DeepFeatureExtractor` above, the `NucleusInstanceSegmentor` engine\n", "returns a single output file when given a single WSI input. Their corresponding\n", "output files are named as `['*/0.dat', '*/1.dat', etc.]` and we need to rename\n", "them accordingly. We generate the cell composition features from each\n", diff --git a/examples/inference-pipelines/slide-graph.ipynb b/examples/inference-pipelines/slide-graph.ipynb index 3b16077ed..0495809de 100644 --- a/examples/inference-pipelines/slide-graph.ipynb +++ b/examples/inference-pipelines/slide-graph.ipynb @@ -443,7 +443,7 @@ "metadata": {}, "outputs": [], "source": [ - "from tiatoolbox.models import FeatureExtractor, IOSegmentorConfig\n", + "from tiatoolbox.models import DeepFeatureExtractor, IOSegmentorConfig\n", "from tiatoolbox.models.architecture import CNNExtractor\n", "\n", "\n", @@ -465,7 +465,7 @@ " save_resolution={\"units\": \"mpp\", \"resolution\": 8.0},\n", " )\n", " model = CNNExtractor(\"resnet50\")\n", - " extractor = FeatureExtractor(\n", + " extractor = DeepFeatureExtractor(\n", " batch_size=32, model=model, num_loader_workers=4)\n", " # Injecting customized preprocessing functions,\n", " # check the document or sample code below for API.\n", @@ -514,10 +514,10 @@ "and count the nuclei of each type in each patch.\n", "We encapsulate this process in the function `get_composition_features`.\n", "\n", - "Unlike the `FeatureExtractor` above, the `NucleusInstanceSegmentor` engine\n", + "Unlike the `DeepFeatureExtractor` above, the `NucleusInstanceSegmentor` engine\n", "returns a single output file given a single WSI input. The corresponding output\n", "files are named as `['*/0.dat', '*/1.dat', etc.]`. Each of these `.dat` files is used to generate\n", - "two files named `*.features.npy` and `*.position.npy`. As in the case of `FeatureExtractor`,\n", + "two files named `*.features.npy` and `*.position.npy`. As in the case of `DeepFeatureExtractor`,\n", "the wildcard _* is, by default, replaced by sequentially ordered names,\n", "for easier management and to avoid inadvertent overwriting." ] diff --git a/tests/models/test_feature_extractor.py b/tests/models/test_feature_extractor.py index 6f56cbcae..798c48e6c 100644 --- a/tests/models/test_feature_extractor.py +++ b/tests/models/test_feature_extractor.py @@ -28,7 +28,7 @@ from tiatoolbox.models.architecture.vanilla import CNNExtractor from tiatoolbox.models.engine.semantic_segmentor import ( - FeatureExtractor, + DeepFeatureExtractor, IOSegmentorConfig, ) from tiatoolbox.wsicore.wsireader import get_wsireader @@ -57,7 +57,7 @@ def test_functional(remote_sample, tmp_path): # * test providing pretrained from torch vs pretrained_model.yaml _rm_dir(save_dir) # default output dir test - extractor = FeatureExtractor(batch_size=1, pretrained_model="fcn-tissue_mask") + extractor = DeepFeatureExtractor(batch_size=1, pretrained_model="fcn-tissue_mask") output_list = extractor.predict( [mini_wsi_svs], mode="wsi", @@ -88,7 +88,7 @@ def test_functional(remote_sample, tmp_path): ) model = CNNExtractor("resnet50") - extractor = FeatureExtractor(batch_size=4, model=model) + extractor = DeepFeatureExtractor(batch_size=4, model=model) # should still run because we skip exception output_list = extractor.predict( [mini_wsi_svs], diff --git a/tiatoolbox/models/__init__.py b/tiatoolbox/models/__init__.py index 9b4c5153b..9a6725c36 100644 --- a/tiatoolbox/models/__init__.py +++ b/tiatoolbox/models/__init__.py @@ -28,7 +28,7 @@ WSIPatchDataset, ) from tiatoolbox.models.engine.semantic_segmentor import ( - FeatureExtractor, + DeepFeatureExtractor, IOSegmentorConfig, SemanticSegmentor, WSIStreamDataset, diff --git a/tiatoolbox/models/engine/semantic_segmentor.py b/tiatoolbox/models/engine/semantic_segmentor.py index 82ecfd06b..bb12cb779 100644 --- a/tiatoolbox/models/engine/semantic_segmentor.py +++ b/tiatoolbox/models/engine/semantic_segmentor.py @@ -1116,7 +1116,7 @@ def predict( return outputs -class FeatureExtractor(SemanticSegmentor): +class DeepFeatureExtractor(SemanticSegmentor): """Generic CNN Feature Extractor. A engine for using any CNN model as a feature extractor. @@ -1152,7 +1152,7 @@ class FeatureExtractor(SemanticSegmentor): >>> wsis = ['A/wsi.svs', 'B/wsi.svs'] >>> # create resnet50 with pytorch pretrained weights >>> model = CNNExtractor('resnet50') - >>> predictor = FeatureExtractor(model=model) + >>> predictor = DeepFeatureExtractor(model=model) >>> output = predictor.predict(wsis, mode='wsi') >>> list(output.keys()) [('A/wsi.svs', 'output/0') , ('B/wsi.svs', 'output/1')] @@ -1300,7 +1300,7 @@ def predict( >>> wsis = ['A/wsi.svs', 'B/wsi.svs'] >>> # create resnet50 with pytorch pretrained weights >>> model = CNNExtractor('resnet50') - >>> predictor = FeatureExtractor(model=model) + >>> predictor = DeepFeatureExtractor(model=model) >>> output = predictor.predict(wsis, mode='wsi') >>> list(output.keys()) [('A/wsi.svs', 'output/0') , ('B/wsi.svs', 'output/1')] From cc6657dd478b576e3ce56ea3517980c6c7c9e426 Mon Sep 17 00:00:00 2001 From: vqdang <24943262+vqdang@users.noreply.github.com> Date: Mon, 20 Dec 2021 16:33:53 +0000 Subject: [PATCH 2/3] [UPD]: update naming --- examples/full-pipelines/slide-graph.ipynb | 4 ++-- examples/inference-pipelines/slide-graph.ipynb | 4 ++-- tests/models/test_feature_extractor.py | 4 ++-- tiatoolbox/models/architecture/__init__.py | 2 +- tiatoolbox/models/architecture/vanilla.py | 4 ++-- tiatoolbox/models/engine/semantic_segmentor.py | 10 +++++----- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/full-pipelines/slide-graph.ipynb b/examples/full-pipelines/slide-graph.ipynb index be6435e43..4e9d83bf1 100644 --- a/examples/full-pipelines/slide-graph.ipynb +++ b/examples/full-pipelines/slide-graph.ipynb @@ -533,7 +533,7 @@ "outputs": [], "source": [ "from tiatoolbox.models import DeepFeatureExtractor, IOSegmentorConfig\n", - "from tiatoolbox.models.architecture import CNNExtractor\n", + "from tiatoolbox.models.architecture import CNNBackbone\n", "\n", "\n", "def extract_deep_features(\n", @@ -553,7 +553,7 @@ " stride_shape=[512, 512],\n", " save_resolution={\"units\": \"mpp\", \"resolution\": 8.0},\n", " )\n", - " model = CNNExtractor(\"resnet50\")\n", + " model = CNNBackbone(\"resnet50\")\n", " extractor = DeepFeatureExtractor(\n", " batch_size=16, model=model, num_loader_workers=4)\n", " # Injecting customized preprocessing functions,\n", diff --git a/examples/inference-pipelines/slide-graph.ipynb b/examples/inference-pipelines/slide-graph.ipynb index 0495809de..7abbe89b5 100644 --- a/examples/inference-pipelines/slide-graph.ipynb +++ b/examples/inference-pipelines/slide-graph.ipynb @@ -444,7 +444,7 @@ "outputs": [], "source": [ "from tiatoolbox.models import DeepFeatureExtractor, IOSegmentorConfig\n", - "from tiatoolbox.models.architecture import CNNExtractor\n", + "from tiatoolbox.models.architecture import CNNBackbone\n", "\n", "\n", "def extract_deep_features(\n", @@ -464,7 +464,7 @@ " stride_shape=[512, 512],\n", " save_resolution={\"units\": \"mpp\", \"resolution\": 8.0},\n", " )\n", - " model = CNNExtractor(\"resnet50\")\n", + " model = CNNBackbone(\"resnet50\")\n", " extractor = DeepFeatureExtractor(\n", " batch_size=32, model=model, num_loader_workers=4)\n", " # Injecting customized preprocessing functions,\n", diff --git a/tests/models/test_feature_extractor.py b/tests/models/test_feature_extractor.py index 798c48e6c..d397072b7 100644 --- a/tests/models/test_feature_extractor.py +++ b/tests/models/test_feature_extractor.py @@ -26,7 +26,7 @@ import numpy as np import torch -from tiatoolbox.models.architecture.vanilla import CNNExtractor +from tiatoolbox.models.architecture.vanilla import CNNBackbone from tiatoolbox.models.engine.semantic_segmentor import ( DeepFeatureExtractor, IOSegmentorConfig, @@ -87,7 +87,7 @@ def test_functional(remote_sample, tmp_path): save_resolution={"units": "mpp", "resolution": 8.0}, ) - model = CNNExtractor("resnet50") + model = CNNBackbone("resnet50") extractor = DeepFeatureExtractor(batch_size=4, model=model) # should still run because we skip exception output_list = extractor.predict( diff --git a/tiatoolbox/models/architecture/__init__.py b/tiatoolbox/models/architecture/__init__.py index 44866f889..63b1598a6 100644 --- a/tiatoolbox/models/architecture/__init__.py +++ b/tiatoolbox/models/architecture/__init__.py @@ -28,7 +28,7 @@ import torch from tiatoolbox import rcParam -from tiatoolbox.models.architecture.vanilla import CNNExtractor, CNNModel +from tiatoolbox.models.architecture.vanilla import CNNBackbone, CNNModel from tiatoolbox.models.dataset.classification import predefined_preproc_func from tiatoolbox.utils.misc import download_data diff --git a/tiatoolbox/models/architecture/vanilla.py b/tiatoolbox/models/architecture/vanilla.py index a66f0688f..621271a71 100644 --- a/tiatoolbox/models/architecture/vanilla.py +++ b/tiatoolbox/models/architecture/vanilla.py @@ -162,7 +162,7 @@ def infer_batch(model, batch_data, on_gpu): return output.cpu().numpy() -class CNNExtractor(ModelABC): +class CNNBackbone(ModelABC): """Retrieve the model backbone and strip the classification layer. This is a wrapper for pretrained models within pytorch. @@ -193,7 +193,7 @@ class CNNExtractor(ModelABC): >>> # Creating resnet50 architecture from default pytorch >>> # without the classification layer with its associated >>> # weights loaded - >>> model = CNNExtractor(backbone="resnet50") + >>> model = CNNBackbone(backbone="resnet50") >>> model.eval() # set to evaluation mode >>> # dummy sample in NHWC form >>> samples = torch.random.rand(4, 3, 512, 512) diff --git a/tiatoolbox/models/engine/semantic_segmentor.py b/tiatoolbox/models/engine/semantic_segmentor.py index bb12cb779..0ad04c045 100644 --- a/tiatoolbox/models/engine/semantic_segmentor.py +++ b/tiatoolbox/models/engine/semantic_segmentor.py @@ -1131,7 +1131,7 @@ class DeepFeatureExtractor(SemanticSegmentor): for processing the data. By default, the corresponding pretrained weights will also be downloaded. However, you can override with your own set of weights via the `pretrained_weights` argument. Argument is case insensitive. - Refer to :class:`tiatoolbox.models.architecture.vanilla.CNNExtractor` + Refer to :class:`tiatoolbox.models.architecture.vanilla.CNNBackbone` for list of supported pretrained models. pretrained_weights (str): Path to the weight of the corresponding `pretrained_model`. @@ -1148,10 +1148,10 @@ class DeepFeatureExtractor(SemanticSegmentor): Examples: >>> # Sample output of a network - >>> from tiatoolbox.models.architecture.vanilla import CNNExtractor + >>> from tiatoolbox.models.architecture.vanilla import CNNBackbone >>> wsis = ['A/wsi.svs', 'B/wsi.svs'] >>> # create resnet50 with pytorch pretrained weights - >>> model = CNNExtractor('resnet50') + >>> model = CNNBackbone('resnet50') >>> predictor = DeepFeatureExtractor(model=model) >>> output = predictor.predict(wsis, mode='wsi') >>> list(output.keys()) @@ -1296,10 +1296,10 @@ def predict( Examples: >>> # Sample output of a network - >>> from tiatoolbox.models.architecture.vanilla import CNNExtractor + >>> from tiatoolbox.models.architecture.vanilla import CNNBackbone >>> wsis = ['A/wsi.svs', 'B/wsi.svs'] >>> # create resnet50 with pytorch pretrained weights - >>> model = CNNExtractor('resnet50') + >>> model = CNNBackbone('resnet50') >>> predictor = DeepFeatureExtractor(model=model) >>> output = predictor.predict(wsis, mode='wsi') >>> list(output.keys()) From 8fc656f8fdf0ff721b2a9ae518327e8e3a78bfae Mon Sep 17 00:00:00 2001 From: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com> Date: Mon, 20 Dec 2021 19:03:08 +0000 Subject: [PATCH 3/3] DEV: Fix requirements_dev.txt - Fix requirements_dev.txt for python 3.7 --- requirements_dev.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 4b5e99347..17f802ba8 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -28,8 +28,8 @@ scikit-image==0.18.3 scikit-learn>=0.23.2 shapely sphinx==4.1.2 -sphinx_gallery -sphinx_toolbox +sphinx-gallery +sphinx-toolbox tifffile torch==1.9.1 torchvision==0.10.1