From f35b340e34272ae9e7ddb64abc32aea4ef754491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ho=CC=88rst?= Date: Fri, 5 Apr 2024 16:35:44 +0200 Subject: [PATCH] Fixing detector path --- .github/workflows/test_build.yml | 2 -- pathopatch/patch_extraction/dataset.py | 2 +- pathopatch/patch_extraction/patch_extraction.py | 4 +++- pathopatch/wsi_interfaces/wsidicomizer_openslide.py | 9 ++++++++- setup.py | 8 +++++--- test.sh | 6 ++++++ test_database/download_links.txt | 1 + .../static_test_files/preprocessing/baseline/config.yaml | 3 +++ 8 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 test.sh diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml index 5f0daa4..4be9277 100644 --- a/.github/workflows/test_build.yml +++ b/.github/workflows/test_build.yml @@ -40,7 +40,5 @@ jobs: run: python -m pytest -vv -s ./tests/test_macenko_module - name : Run Core Tests run: python -m pytest -vv -s ./tests/test_core_modules - - name : Run Dicom Tests - run: python -m pytest -vv -s ./tests/test_dicom_module - name : Run Dataset and Dataloader Tests run: python -m pytest -vv -s ./tests/test_pytorch_dataset diff --git a/pathopatch/patch_extraction/dataset.py b/pathopatch/patch_extraction/dataset.py index 550fff8..682f0e9 100644 --- a/pathopatch/patch_extraction/dataset.py +++ b/pathopatch/patch_extraction/dataset.py @@ -325,7 +325,7 @@ def _set_tissue_detector(self) -> None: model = mobilenet_v3_small().to(device=self.detector_device) model.classifier[-1] = nn.Linear(1024, 4) checkpoint = torch.load( - "./pathopatch/data/tissue_detector.pt", # this causes errors + "/pathopatch/data/tissue_detector.pt", # this causes errors map_location=self.detector_device, ) model.load_state_dict(checkpoint["model_state_dict"]) diff --git a/pathopatch/patch_extraction/patch_extraction.py b/pathopatch/patch_extraction/patch_extraction.py index a489a23..124ee7a 100644 --- a/pathopatch/patch_extraction/patch_extraction.py +++ b/pathopatch/patch_extraction/patch_extraction.py @@ -478,7 +478,9 @@ def _set_tissue_detector(self) -> None: model = mobilenet_v3_small().to(device=self.detector_device) model.classifier[-1] = nn.Linear(1024, 4) checkpoint = torch.load( - "./pathopatch/data/tissue_detector.pt", # this causes errors + ( + Path(os.path.dirname(__file__)).parent / "data" / "tissue_detector.pt" + ).resolve(), map_location=self.detector_device, ) model.load_state_dict(checkpoint["model_state_dict"]) diff --git a/pathopatch/wsi_interfaces/wsidicomizer_openslide.py b/pathopatch/wsi_interfaces/wsidicomizer_openslide.py index 1bfe599..9c2af22 100644 --- a/pathopatch/wsi_interfaces/wsidicomizer_openslide.py +++ b/pathopatch/wsi_interfaces/wsidicomizer_openslide.py @@ -17,7 +17,14 @@ def __init__(self, dcm_folder: Union[Path, str]) -> None: self.level_count: int self.level_downsamples: List[float] - source = WsiDicomFileSource.open(dcm_folder) + # iterate through the folder to check if a DICOMDIR file exists + dcm_folder = Path(dcm_folder) + files = [f for f in dcm_folder.iterdir() if f.is_file()] + if not any(f.name == "DICOMDIR" for f in files): + source = WsiDicomFileSource.open(dcm_folder) + else: + source = WsiDicomFileSource.open_dicomdir(dcm_folder / "DICOMDIR") + super().__init__(source, True) # information and properties to make this compatible with OpenSlide diff --git a/setup.py b/setup.py index 6213ee4..ab25738 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "1.0.1b" +VERSION = "1.0.4b" DESCRIPTION = "PathoPatch - Accelerating Artificial Intelligence Based Whole Slide Image Analysis with an Optimized Preprocessing Pipeline" with open("docs/README_pypi.md", "r") as fh: LONG_DESCRIPTION = fh.read() @@ -39,8 +39,8 @@ "tqdm", "torchvision", "torch", - "wsidicom=0.20.4", - "wsidicomizer=0.13.2", + "wsidicom==0.20.4", + "wsidicomizer==0.13.2", ], scripts=[ "pathopatch/wsi_extraction.py", @@ -64,4 +64,6 @@ "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Other", ], + include_package_data=True, + package_data={"pathopatch": ["data/*"]}, ) diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..0d7bbb0 --- /dev/null +++ b/test.sh @@ -0,0 +1,6 @@ +python -m pytest -vv -s ./tests/test_cli +python -m pytest -vv -s ./tests/test_utils +python -m pytest -vv -s ./tests/test_macenko_module +python -m pytest -vv -s ./tests/test_core_modules +python -m pytest -vv -s ./tests/test_dicom_module +python -m pytest -vv -s ./tests/test_pytorch_dataset diff --git a/test_database/download_links.txt b/test_database/download_links.txt index 9e5bafc..e13ce5b 100644 --- a/test_database/download_links.txt +++ b/test_database/download_links.txt @@ -1,3 +1,4 @@ https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/CMU-1.svs https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/CMU-1-Small-Region.svs https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/JP2K-33003-1.svs +https://drive.google.com/uc?export=download&id=15EjjYxtWf3_o_H4REckK1A0A8JGbpWC6 diff --git a/tests/static_test_files/preprocessing/baseline/config.yaml b/tests/static_test_files/preprocessing/baseline/config.yaml index d730699..e975c3d 100644 --- a/tests/static_test_files/preprocessing/baseline/config.yaml +++ b/tests/static_test_files/preprocessing/baseline/config.yaml @@ -10,3 +10,6 @@ processes: 8 # other log_level: debug overwrite: True + +apply_prefilter: True +filter_patches: True