Skip to content

Commit

Permalink
Merge pull request #2 from TIO-IKIM/setup
Browse files Browse the repository at this point in the history
Adding build
  • Loading branch information
FabianHoerst authored Jan 12, 2024
2 parents f4fafce + 2f63c32 commit 0f19109
Show file tree
Hide file tree
Showing 46 changed files with 226 additions and 115 deletions.
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ notebooks

# local configs
.vscode
Tissue-Classifier-Data
tests_backup
tests/static_test_files/preprocessing/basic
tests/static_test_files/preprocessing/complex_annotation
tests/static_test_files/preprocessing/custom
tests/static_test_files/preprocessing/overlap
tests/tmp_results_folder/*
output

# Build
pathopatch.egg-info/
dist
build
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://github.com/TIO-IKIM/PathoPatcher">PathoPatcher</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://github.com/FabianHoerst">Fabian Hörst, University Hospital Essen,</a> is licensed under <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-SA 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1"></a></p>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,6 @@ TBD
## Citation
TBD
## License
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://github.com/TIO-IKIM/PathoPatcher">PathoPatcher</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://github.com/FabianHoerst">Fabian Hörst, University Hospital Essen,</a> is licensed under <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-SA 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1"></a></p>
30 changes: 1 addition & 29 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,31 @@ channels:
- defaults
dependencies:
- python=3.10.12
- openslide=3.4.1
- openslide=4.0.0
- pip=23.0
- python-javabridge
- pip:
- Pillow==9.5.0
- PyYAML==6.0
- Shapely==1.8.5.post1
- SimpleITK==2.2.1
- albumentations==1.3.0
- black==23.1.0
- csbdeep==0.7.4
- colorama==0.4.6
- einops==0.6.1
- flake8-html==0.4.3
- flake8==6.0.0
- future==0.18.2
- genbadge==1.1.0
- geojson==3.0.0
- h5py==3.9.0
- histolab==0.6.0
- imageio==2.31.1
- ipython-genutils==0.2.0
- jupyterlab==4.0.2
- kaleido==0.2.1
- keras==2.12.0
- keras==2.12.0
- mako==1.2.4
- matplotlib==3.7.1
- natsort==8.4.0
- numpy>1.22,<1.24
- opencv_python_headless==4.5.4.58
- openslide_python==1.2.0
- pandarallel==1.6.5
- pandas==1.5.3
- pre-commit==3.0.3
- pydantic==1.10.4
- pyjwt==2.6.0
- pytest==7.4.4
- pytest-sugar==0.9.7
- rasterio==1.3.5.post1
- schema==0.7.5
- scikit-image==0.19.3
- scikit-learn==1.2.1
- scikit-survival==0.21.0
- scipy>1.5.0,<=1.8.2
- seaborn==0.12.2
- sqlalchemy==2.0.17
- stardist==0.8.5
- tabulate==0.9.0
- tensorflow==2.12.0
- torchinfo==1.8.0
- torchmetrics==0.11.4
- torchvision==0.16.2
- tqdm==4.65.0
- ujson==5.8.0
- wandb==0.15.4
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# -*- coding: utf-8 -*-
# Geojson annotation preprocessing
#
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions pathopatcher/cli.py → pathopatch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import yaml
from pydantic import BaseModel, validator

from pathopatcher.base_ml.base_cli import ABCParser
from pathopatcher.config.config import ANNOTATION_EXT, LOGGING_EXT, WSI_EXT
from pathopatcher.utils.logger import Logger
from pathopatch.base_ml.base_cli import ABCParser
from pathopatch.config.config import ANNOTATION_EXT, LOGGING_EXT, WSI_EXT
from pathopatch.utils.logger import Logger


class PreProcessingYamlConfig(BaseModel):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/usr/bin/env python

# -*- coding: utf-8 -*-
# Main entry point for Macenko
#
# @ Fabian Hörst, [email protected]
# Institute for Artifical Intelligence in Medicine,
# University Medicine Essen

import inspect
import logging
import os
Expand All @@ -15,10 +23,11 @@
parentdir = os.path.dirname(parentdir)
sys.path.insert(0, parentdir)

from pathopatcher.cli import MacenkoParser
from pathopatcher.patch_extraction.patch_extraction import PreProcessor
from pathopatch.cli import MacenkoParser
from pathopatch.patch_extraction.patch_extraction import PreProcessor

if __name__ == "__main__":

def main():
configuration_parser = MacenkoParser()
configuration, logger = configuration_parser.get_config()

Expand All @@ -28,3 +37,7 @@
)

logger.info("Finished Macenko Vector Calculation!")


if __name__ == "__main__":
main()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
from shapely.geometry import Polygon
from tqdm import tqdm

from pathopatcher import logger
from pathopatcher.cli import PreProcessingConfig
from pathopatcher.patch_extraction.storage import Storage
from pathopatcher.utils.exceptions import (
from pathopatch import logger
from pathopatch.cli import PreProcessingConfig
from pathopatch.patch_extraction.storage import Storage
from pathopatch.utils.exceptions import (
UnalignedDataException,
WrongParameterException,
)
from pathopatcher.utils.patch_dataset import load_tissue_detection_dl
from pathopatcher.utils.patch_util import (
from pathopatch.utils.patch_dataset import load_tissue_detection_dl
from pathopatch.utils.patch_util import (
DeepZoomGeneratorOS,
calculate_background_ratio,
compute_interesting_patches,
Expand All @@ -55,7 +55,7 @@
target_mag_to_downsample,
target_mpp_to_downsample,
)
from pathopatcher.utils.tools import end_timer, module_exists, start_timer
from pathopatch.utils.tools import end_timer, module_exists, start_timer

warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=UserWarning)
Expand Down Expand Up @@ -414,7 +414,7 @@ def _set_hardware(self, hardware_selection: str = "cucim") -> None:
logger.info("Using CuCIM")
from cucim import CuImage

from pathopatcher.patch_extraction.cucim_deepzoom import (
from pathopatch.patch_extraction.cucim_deepzoom import (
DeepZoomGeneratorCucim,
)

Expand Down Expand Up @@ -458,7 +458,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(
"./pathopatcher/data/tissue_detector.pt",
"./pathopatch/data/tissue_detector.pt", # this causes errors
map_location=self.detector_device,
)
model.load_state_dict(checkpoint["model_state_dict"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from PIL import Image
from shapely.geometry import Polygon

from pathopatcher.utils.patch_util import (
from pathopatch.utils.patch_util import (
DeepZoomGeneratorOS,
calculate_background_ratio,
get_intersected_labels,
Expand All @@ -24,9 +24,9 @@
patch_to_tile_size,
standardize_brightness,
)
from pathopatcher.utils.tools import module_exists
from pathopatch.utils.tools import module_exists

from pathopatcher import logger
from pathopatch import logger


def process_batch(
Expand Down Expand Up @@ -107,7 +107,7 @@ def process_batch(
if module_exists("cucim", error="ignore"):
from cucim import CuImage

from pathopatcher.deepzoom.cucim_deepzoom import DeepZoomGeneratorCucim
from pathopatch.deepzoom.cucim_deepzoom import DeepZoomGeneratorCucim

generator_module = DeepZoomGeneratorCucim
image_loader = CuImage
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sys

from colorama import init
from pathopatcher.config.config import COLOR_CODES_LOGGING
from pathopatch.config.config import COLOR_CODES_LOGGING

init(autoreset=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from shapely.affinity import scale
from shapely.geometry import Polygon

from pathopatcher import logger
from pathopatch import logger


def generate_tissue_mask(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
from shapely.geometry import Polygon, shape
from shapely.validation import make_valid

from pathopatcher import logger
from pathopatcher.utils.exceptions import WrongParameterException
from pathopatcher.utils.masking import (
from pathopatch import logger
from pathopatch.utils.exceptions import WrongParameterException
from pathopatch.utils.masking import (
convert_polygons_to_mask,
generate_tissue_mask,
)
from pathopatcher.utils.plotting import generate_polygon_overview
from pathopatch.utils.plotting import generate_polygon_overview


def get_files_from_dir(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from rasterio.mask import mask as rasterio_mask
from shapely.geometry import Polygon

from pathopatcher.config.config import COLOR_DEFINITIONS
from pathopatcher.utils.masking import get_filtered_polygons
from pathopatch.config.config import COLOR_DEFINITIONS
from pathopatch.utils.masking import get_filtered_polygons


def generate_polygon_overview(
Expand Down
2 changes: 1 addition & 1 deletion pathopatcher/utils/tools.py → pathopatch/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from timeit import default_timer as timer
from typing import Dict, List, Optional, Tuple, Union

from pathopatcher import logger
from pathopatch import logger


# Helper timing functions
Expand Down
23 changes: 15 additions & 8 deletions pathopatcher/main_extraction.py → pathopatch/wsi_extraction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# -*- coding: utf-8 -*-
# Main entry point for patch-preprocessing
#
Expand All @@ -8,21 +10,22 @@
import sys
import os

project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.append(project_root)
project_root = os.path.dirname(os.path.abspath(project_root))
sys.path.append(project_root)
# project_root = os.path.dirname(os.path.abspath(__file__))
# sys.path.append(project_root)
# project_root = os.path.dirname(os.path.abspath(project_root))
# sys.path.append(project_root)

import logging

logger = logging.getLogger()
logger.addHandler(logging.NullHandler())

from pathopatcher.cli import PreProcessingParser
from pathopatcher.patch_extraction.patch_extraction import PreProcessor
from pathopatcher.utils.tools import close_logger
from pathopatch.cli import PreProcessingParser
from pathopatch.patch_extraction.patch_extraction import PreProcessor
from pathopatch.utils.tools import close_logger

if __name__ == "__main__":

def main():
configuration_parser = PreProcessingParser()
configuration, logger = configuration_parser.get_config()
configuration_parser.store_config()
Expand All @@ -32,3 +35,7 @@

logger.info("Finished Preprocessing.")
close_logger(logger)


if __name__ == "__main__":
main()
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Pillow>=9.5.0
PyYAML
Shapely==1.8.5.post1
colorama
future
geojson==3.0.0
histolab==0.6.0
matplotlib
natsort
numpy>1.22,<1.24
opencv_python_headless
openslide_python
pandas
pydantic==1.10.4
rasterio==1.3.5.post1
requests
scikit-image
setuptools<=65.6.3
tqdm
torchvision
torch
27 changes: 27 additions & 0 deletions requirements_develop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Pillow>=9.5.0
PyYAML
Shapely==1.8.5.post1
black
colorama
flake8
flake8-html
genbadge
geojson==3.0.0
histolab==0.6.0
matplotlib
natsort
numpy>1.22,<1.24
opencv_python_headless
openslide_python
pandas
pre-commit
pydantic==1.10.4
pytest
pytest-sugar
rasterio==1.3.5.post1
requests
scikit-image
setuptools<=65.6.3
tqdm
torchvision
torch
Loading

0 comments on commit 0f19109

Please sign in to comment.