wsi-patching 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wsi_patching-0.5.0/.github/workflows/docs.yml +25 -0
- wsi_patching-0.5.0/.github/workflows/integration_tests.yaml +41 -0
- wsi_patching-0.5.0/.github/workflows/publish.yaml +35 -0
- wsi_patching-0.5.0/.github/workflows/unit_tests.yaml +41 -0
- wsi_patching-0.5.0/.gitignore +213 -0
- wsi_patching-0.5.0/LICENSE +21 -0
- wsi_patching-0.5.0/PKG-INFO +249 -0
- wsi_patching-0.5.0/README.md +187 -0
- wsi_patching-0.5.0/docs/concepts.md +124 -0
- wsi_patching-0.5.0/docs/extending.md +171 -0
- wsi_patching-0.5.0/docs/index.md +42 -0
- wsi_patching-0.5.0/docs/installation.md +45 -0
- wsi_patching-0.5.0/docs/quickstart.md +96 -0
- wsi_patching-0.5.0/docs/reference.md +275 -0
- wsi_patching-0.5.0/examples/numpy_stream_writer_demo.py +35 -0
- wsi_patching-0.5.0/examples/torch_stream_writer_demo.py +37 -0
- wsi_patching-0.5.0/examples/webdataset_materialize_writer_demo.py +56 -0
- wsi_patching-0.5.0/mkdocs.yml +54 -0
- wsi_patching-0.5.0/pyproject.toml +94 -0
- wsi_patching-0.5.0/src/wsi_patching/__init__.py +38 -0
- wsi_patching-0.5.0/src/wsi_patching/annotations/__init__.py +3 -0
- wsi_patching-0.5.0/src/wsi_patching/annotations/add_cell_annotation_from_csv.py +152 -0
- wsi_patching-0.5.0/src/wsi_patching/assets/models/cellvit_tissue_detector.pt +0 -0
- wsi_patching-0.5.0/src/wsi_patching/backends/__init__.py +0 -0
- wsi_patching-0.5.0/src/wsi_patching/backends/cupy_numpy.py +80 -0
- wsi_patching-0.5.0/src/wsi_patching/backends/fastslide.py +243 -0
- wsi_patching-0.5.0/src/wsi_patching/backends/torch_device.py +45 -0
- wsi_patching-0.5.0/src/wsi_patching/core/__init__.py +4 -0
- wsi_patching-0.5.0/src/wsi_patching/core/chunking_and_batching.py +519 -0
- wsi_patching-0.5.0/src/wsi_patching/core/pipeline.py +566 -0
- wsi_patching-0.5.0/src/wsi_patching/core/types/__init__.py +0 -0
- wsi_patching-0.5.0/src/wsi_patching/core/types/types.py +145 -0
- wsi_patching-0.5.0/src/wsi_patching/core/types/util_types.py +93 -0
- wsi_patching-0.5.0/src/wsi_patching/core/wsi_grid.py +119 -0
- wsi_patching-0.5.0/src/wsi_patching/custom_component/__init__.py +18 -0
- wsi_patching-0.5.0/src/wsi_patching/encoders/__init__.py +3 -0
- wsi_patching-0.5.0/src/wsi_patching/encoders/pngencoder.py +72 -0
- wsi_patching-0.5.0/src/wsi_patching/filtering/__init__.py +15 -0
- wsi_patching-0.5.0/src/wsi_patching/filtering/cellvit_tissue_classifier_filter.py +124 -0
- wsi_patching-0.5.0/src/wsi_patching/filtering/low_contrast_background_filter.py +125 -0
- wsi_patching-0.5.0/src/wsi_patching/filtering/otsu_filter.py +217 -0
- wsi_patching-0.5.0/src/wsi_patching/filtering/pen_artifact_filter.py +216 -0
- wsi_patching-0.5.0/src/wsi_patching/py.typed +0 -0
- wsi_patching-0.5.0/src/wsi_patching/regions_of_interest/__init__.py +4 -0
- wsi_patching-0.5.0/src/wsi_patching/regions_of_interest/attach_rois.py +59 -0
- wsi_patching-0.5.0/src/wsi_patching/regions_of_interest/roi_providers.py +94 -0
- wsi_patching-0.5.0/src/wsi_patching/regions_of_interest/rois.py +78 -0
- wsi_patching-0.5.0/src/wsi_patching/transforms/__init__.py +4 -0
- wsi_patching-0.5.0/src/wsi_patching/transforms/macenko_normalizer.py +175 -0
- wsi_patching-0.5.0/src/wsi_patching/transforms/reinhard_normalizer.py +271 -0
- wsi_patching-0.5.0/src/wsi_patching/utils/__init__.py +3 -0
- wsi_patching-0.5.0/src/wsi_patching/utils/logging_config.py +13 -0
- wsi_patching-0.5.0/src/wsi_patching/utils/meta_typing.py +94 -0
- wsi_patching-0.5.0/src/wsi_patching/utils/profiling.py +115 -0
- wsi_patching-0.5.0/src/wsi_patching/utils/wsi_thumbnail_visualization.py +208 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/__init__.py +10 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/materialize_writers/__init__.py +0 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/materialize_writers/materialize_writer_base.py +92 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/materialize_writers/webdataset/__init__.py +0 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/materialize_writers/webdataset/webdataset_loader.py +165 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/materialize_writers/webdataset/webdataset_writer.py +69 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/stream_writers/__init__.py +0 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/stream_writers/numpy_stream_writer.py +36 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/stream_writers/stream_writer_base.py +71 -0
- wsi_patching-0.5.0/src/wsi_patching/writers/stream_writers/torch_stream_writer.py +67 -0
- wsi_patching-0.5.0/tests/benchmarks/conftest.py +34 -0
- wsi_patching-0.5.0/tests/benchmarks/test_benchmark_pipeline.py +36 -0
- wsi_patching-0.5.0/tests/benchmarks/test_benchmark_png_encoding.py +44 -0
- wsi_patching-0.5.0/tests/benchmarks/test_benchmark_tile_planning.py +45 -0
- wsi_patching-0.5.0/tests/integration/conftest.py +69 -0
- wsi_patching-0.5.0/tests/integration/test_materialize_pipeline.py +24 -0
- wsi_patching-0.5.0/tests/integration/test_resample_pipeline.py +86 -0
- wsi_patching-0.5.0/tests/integration/test_roi_pipeline.py +35 -0
- wsi_patching-0.5.0/tests/integration/test_streaming_pipeline.py +30 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/.gitkeep +0 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/annotations/test_add_cell_annotation_from_csv.py +146 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/backends/test_cupy_numpy.py +95 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/backends/test_fastslide.py +447 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/backends/test_torch_device.py +39 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/core/test_chunking_and_batching.py +541 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/core/test_pipeline.py +123 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/core/test_wsi_grid.py +175 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/filtering/test_cellvit_tissue_classifier_filter.py +95 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/filtering/test_low_contrast_background_filter.py +201 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/filtering/test_otsu_filter.py +177 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/filtering/test_pen_artifact_filter.py +156 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/regions_of_interest/test_attach_rois.py +92 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/regions_of_interest/test_roi_providers.py +331 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/regions_of_interest/test_rois.py +47 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/transforms/test_macenko_normalizer.py +421 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/transforms/test_reinhard_normalizer.py +92 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/utils/test_logging_config.py +52 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/utils/test_meta_typing.py +99 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/utils/test_profiling.py +135 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/writers/materialize_writers/test_materialize_writer_base.py +161 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/writers/materialize_writers/webdataset/test_webdataset_loader.py +177 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/writers/materialize_writers/webdataset/test_webdataset_writer.py +121 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/writers/stream_writers/test_numpy_stream_writer.py +114 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/writers/stream_writers/test_stream_writer_base.py +104 -0
- wsi_patching-0.5.0/tests/unit/src/wsi_patching/writers/stream_writers/test_torch_stream_writer.py +134 -0
- wsi_patching-0.5.0/uv.lock +1531 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Deploy docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths:
|
|
7
|
+
- docs/**
|
|
8
|
+
- mkdocs.yml
|
|
9
|
+
# tags:
|
|
10
|
+
# - "v*.*.*"
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: write
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
deploy:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
cache: pip
|
|
24
|
+
- run: pip install mkdocs-material
|
|
25
|
+
- run: mkdocs gh-deploy --force
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CPU integration tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths: &paths
|
|
7
|
+
- src/wsi_patching/**
|
|
8
|
+
- tests/integration/**
|
|
9
|
+
- .github/workflows/integration_tests.yaml
|
|
10
|
+
|
|
11
|
+
pull_request:
|
|
12
|
+
branches: [main]
|
|
13
|
+
paths: *paths
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
pytest:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
strategy:
|
|
19
|
+
matrix:
|
|
20
|
+
python-version: ${{ fromJson( ((github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags/')) && '["3.10","3.11","3.12","3.13"]' || '["3.10","3.13"]' ) }}
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
|
|
26
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
+
uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: ${{ matrix.python-version }}
|
|
30
|
+
cache: pip
|
|
31
|
+
|
|
32
|
+
- name: Install project (dev extras)
|
|
33
|
+
run: |
|
|
34
|
+
pip install --upgrade pip
|
|
35
|
+
pip install -e .[dev]
|
|
36
|
+
|
|
37
|
+
- name: Install CPU torch for GPU-optional tests
|
|
38
|
+
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
|
39
|
+
|
|
40
|
+
- name: Run tests
|
|
41
|
+
run: pytest tests/integration
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*.*.*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Build and publish
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: pypi
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write # required for OIDC trusted publisher
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0 # needed for hatch-vcs to resolve the tag
|
|
20
|
+
|
|
21
|
+
- name: Ensure tag is on main
|
|
22
|
+
run: |
|
|
23
|
+
git fetch origin main
|
|
24
|
+
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
|
|
25
|
+
echo "Tagged commit is not on main. Aborting."
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
- uses: astral-sh/setup-uv@v5
|
|
30
|
+
|
|
31
|
+
- name: Build
|
|
32
|
+
run: uv build
|
|
33
|
+
|
|
34
|
+
- name: Publish to PyPI
|
|
35
|
+
run: uv publish
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CPU unit tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths: &unit_paths
|
|
7
|
+
- src/wsi_patching/**
|
|
8
|
+
- tests/unit/**
|
|
9
|
+
- .github/workflows/unit_tests.yaml
|
|
10
|
+
|
|
11
|
+
pull_request:
|
|
12
|
+
branches: [main]
|
|
13
|
+
paths: *unit_paths
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
pytest:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
strategy:
|
|
19
|
+
matrix:
|
|
20
|
+
python-version: ${{ fromJson( ((github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags/')) && '["3.10","3.11","3.12","3.13"]' || '["3.10","3.13"]' ) }}
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout
|
|
24
|
+
uses: actions/checkout@v4
|
|
25
|
+
|
|
26
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
27
|
+
uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: ${{ matrix.python-version }}
|
|
30
|
+
cache: pip
|
|
31
|
+
|
|
32
|
+
- name: Install project (dev extras)
|
|
33
|
+
run: |
|
|
34
|
+
pip install --upgrade pip
|
|
35
|
+
pip install -e .[dev]
|
|
36
|
+
|
|
37
|
+
- name: Install CPU torch for GPU-optional tests
|
|
38
|
+
run: pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
|
39
|
+
|
|
40
|
+
- name: Run tests
|
|
41
|
+
run: pytest tests/unit
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
.vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
data/
|
|
211
|
+
output/
|
|
212
|
+
inference_gpu_runner.sh
|
|
213
|
+
CLAUDE.md
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Robin van Hoorn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wsi-patching
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: A High Performance Patching Library for Digital Pathology AI dataset creation.
|
|
5
|
+
Project-URL: Homepage, https://github.com/amspath/wsi-patching-pipeline
|
|
6
|
+
Project-URL: Repository, https://github.com/amspath/wsi-patching-pipeline
|
|
7
|
+
Author-email: Robin van Hoorn <r.d.vanhoorn@amsterdamumc.nl>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2024 Robin van Hoorn
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: WSI,deep learning,digital pathology,medical imaging,patching,whole slide image
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Science/Research
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
40
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
41
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
42
|
+
Requires-Python: <3.14,>=3.10
|
|
43
|
+
Requires-Dist: fastslide==0.5.2
|
|
44
|
+
Requires-Dist: numpy>=1.24
|
|
45
|
+
Requires-Dist: opencv-python-headless>=4.8
|
|
46
|
+
Requires-Dist: orjson>=3.8
|
|
47
|
+
Requires-Dist: pillow>=9.0
|
|
48
|
+
Requires-Dist: rtree>=1.0
|
|
49
|
+
Requires-Dist: webdataset>=0.2.86
|
|
50
|
+
Provides-Extra: dev
|
|
51
|
+
Requires-Dist: mkdocs-material; extra == 'dev'
|
|
52
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
53
|
+
Requires-Dist: pytest-benchmark; extra == 'dev'
|
|
54
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
55
|
+
Requires-Dist: tifffile; extra == 'dev'
|
|
56
|
+
Requires-Dist: ty; extra == 'dev'
|
|
57
|
+
Provides-Extra: gpu
|
|
58
|
+
Requires-Dist: cupy-cuda12x; (platform_system != 'Darwin') and extra == 'gpu'
|
|
59
|
+
Requires-Dist: torch; extra == 'gpu'
|
|
60
|
+
Requires-Dist: torchvision; extra == 'gpu'
|
|
61
|
+
Description-Content-Type: text/markdown
|
|
62
|
+
|
|
63
|
+
[](https://github.com/amspath/wsi-patching-pipeline/actions/workflows/unit_tests.yaml)
|
|
64
|
+
[](https://github.com/amspath/wsi-patching-pipeline/actions/workflows/integration_tests.yaml)
|
|
65
|
+
|
|
66
|
+
# wsi-patching-pipeline
|
|
67
|
+
A pragmatic pipeline for streaming whole-slide image (WSI) patches with region prefetch, per-WSI multiprocessing producers, and an async writer. It's ideal for building pipelines that create datasets, or for patching in a streaming fashion during inference without overloading your memory. It’s designed as a runnable skeleton you can extend: swap in your own ROI logic, classifiers, encoders, or sinks by building components on the `custom_component` module facilities.
|
|
68
|
+
|
|
69
|
+
✨ What you get
|
|
70
|
+
- Streaming, regionized tiling of WSIs.
|
|
71
|
+
- Per-slide producers (theading) feeding a bounded queue.
|
|
72
|
+
- Single writer process for continuous writing in the sink (i.e. to a webdataset, or numpy arrays).
|
|
73
|
+
- Batched GPU steps.
|
|
74
|
+
- Built-in isolated stage profiling per slide + aggregated stats.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## 1) Library install
|
|
78
|
+
|
|
79
|
+
Python ≥3.10 <3.14 is recommended. 3.14 is yet unsupported.
|
|
80
|
+
```
|
|
81
|
+
# CPU install
|
|
82
|
+
pip install "wsi-patching @ git+https://github.com/amspath/wsi-patching-pipeline.git"
|
|
83
|
+
|
|
84
|
+
# GPU install
|
|
85
|
+
pip install "wsi-patching[gpu] @ git+https://github.com/amspath/wsi-patching-pipeline.git"
|
|
86
|
+
```
|
|
87
|
+
> For some stages, GPUs are required, and thus the GPU install is required.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## 2) Checkout the examples
|
|
91
|
+
`numpy_mem_writer_demo.py` shows you how to build a basic pipeline for patching up a wsi in memory, without the need of writing to disk (RAM heavy for larger datasets, obviously).
|
|
92
|
+
```python
|
|
93
|
+
p = (
|
|
94
|
+
WSIGrid(slides=slides, resolution=0, unit="level", use_gpu=True)
|
|
95
|
+
.then(PatchExtractor(tile_size=256, stride=256, max_batch_size=800, num_workers=4))
|
|
96
|
+
.then(LowContrastBackgroundFilter(range_threshold=0.2))
|
|
97
|
+
.then(ReinhardNormalizer())
|
|
98
|
+
.to(NumpyMemoryWriter(layout="NCHW"))
|
|
99
|
+
)
|
|
100
|
+
stream = p.stream(num_workers=4)
|
|
101
|
+
for wsi_id, final_images, final_coords, meta in stream:
|
|
102
|
+
...
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
> Useful to know: Stream writers do not order the patches per WSI. This improves speed. You can check the wsi_id returned from the stream to check which WSI each batch belongs to. If you per se want ordered batches, you can set the num_workers to 1.
|
|
106
|
+
|
|
107
|
+
`webdataset_materialize_writer_demo.py` shows you how to build a basic pipeline for creating a WebDataset (A materializing pipeline)
|
|
108
|
+
```python
|
|
109
|
+
p = (
|
|
110
|
+
WSIGrid(slides=slides, resolution=0, unit="level")
|
|
111
|
+
.then(AttachROIs(providers=[RectROIProvider(rois_dict)]))
|
|
112
|
+
.then(PatchExtractor(tile_size=224, stride=224))
|
|
113
|
+
.then(PNGEncoder())
|
|
114
|
+
.to(WebDatasetWriter(shard_size=300, shuffle_buffer_size=500))
|
|
115
|
+
)
|
|
116
|
+
p.materialize(num_workers=4)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## 3) Check out the currently available components:
|
|
120
|
+
#### Core components
|
|
121
|
+
- `WSIGrid`: Your starter block
|
|
122
|
+
- `AttachROIs`: Attach an ROI provider class to ensure that only your regions of interest are patched up. There are two basic ROI providers implemented, being a `RectROIProvider`, and a `RectROIfromXMLProvider`. More to come when needed.
|
|
123
|
+
- `PatchExtractor`: A necessary component in every pipeline. This will nicely read and batch up all your patches. The PatchExtractor is a composite stage, which contains three stages. If you want to adapt the PatchExtractor logic, you can individually add the substages to your pipeline and swap out stages for custom ones.
|
|
124
|
+
- A sink component to define what the output should be. There are two types of writers:
|
|
125
|
+
- `MaterializeWriterBase` writers: For writers that materialize data (i.e. write to disk). These types of writers are particularly useful for making large training datasets. Examples include:
|
|
126
|
+
- `WebdatasetWriter`: For writing to/creating a webdataset.
|
|
127
|
+
- `StreamWriterBase` writers: For writers that stream batches of data to memory. These types of writers are particularly useful for patching during inference or in any situation where you don't necessarily want to write to your disk. Examples include:
|
|
128
|
+
- `NumpyStreamWriter`: For obtaining numpy patches.
|
|
129
|
+
- `TorchStreamWriter`: For obtaining torch tensors.
|
|
130
|
+
|
|
131
|
+
#### Other components
|
|
132
|
+
- Filters: For filtering out your patches that you do not need
|
|
133
|
+
- `LowContrastBackgroundFilter`: A simple filter for filtering out background with very little difference between pixels.
|
|
134
|
+
- `OtsuFilter`: Applying otsu's method and filtering on a threshold.
|
|
135
|
+
- `PenArtifactFilter`: Applying histolabs blue, green and red pen filters, but using our own batched, gpu accelerated implementation.
|
|
136
|
+
- `CellVitTissueClassifierFilter`: Using CellVits original tissue classifier, it classifies patches as background using a mobilenetv3.
|
|
137
|
+
- Transforms: For transforming your patches
|
|
138
|
+
- `Macenko Normalizer`: Applies Macenko normalizer, fitting on the first batch it encounters (watch out for the first batch being a background batch).
|
|
139
|
+
- `Reinhard Normalizer`: Applies Reinhard normalizer with the reference LAB color mean and std statistics provided. Uses this configuration by default (computed for "golden" kidney AUMC scans):
|
|
140
|
+
```
|
|
141
|
+
lab_reference_mean = [68.94, 29.76, -18.97]
|
|
142
|
+
lab_reference_std = [11.52, 13.42, 8.59]
|
|
143
|
+
```
|
|
144
|
+
- Encoders: For encoding your patches into the right format
|
|
145
|
+
- `PNGEncoder` Transforming your patches into PNGs. Particularly useful for the WebDatasetWriter.
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
More to come! Request if you would like your stage to be in the library.
|
|
149
|
+
|
|
150
|
+
## 4) Build your own components
|
|
151
|
+
This library is setup such that you can easily build your own components to suit your own needs and pop it into the pipeline. Components can either extend the `Stage` (a processing stage) or `WriterBase` (a sink) components.
|
|
152
|
+
|
|
153
|
+
#### Creating a stage component:
|
|
154
|
+
```python
|
|
155
|
+
from wsi_patching.custom_component import Stage, PipelineContext, # <PreviousStageOutputType> and <NextStageInputType> can also be found here
|
|
156
|
+
|
|
157
|
+
class CustomStage(Stage):
|
|
158
|
+
def __init__(self, ...):
|
|
159
|
+
...
|
|
160
|
+
|
|
161
|
+
def export_context(self, ctx: "PipelineContext") -> None:
|
|
162
|
+
# Optional: Seed/override global grid parameters for other stages to read, i.e.
|
|
163
|
+
ctx["tile_size"] = self.tile_size
|
|
164
|
+
def validate(self) -> None:
|
|
165
|
+
# Optional: Validate your class before starting processing, i.e.
|
|
166
|
+
self.ctx.require_key("use_gpu")
|
|
167
|
+
if self.ctx['some_key'] < self.some_init_param:
|
|
168
|
+
...
|
|
169
|
+
|
|
170
|
+
def __call__(self, it: Iterable[<PreviousStageOutputType>]) -> Iterable[<NextStageInputType>]:
|
|
171
|
+
# The logic of your stage. You should specifiy the type of your call function.
|
|
172
|
+
# These should align with the preceeding and succeeding stages (checked at initialization).
|
|
173
|
+
...
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### Creating a custom sink component:
|
|
177
|
+
```python
|
|
178
|
+
from wsi_patching.custom_component import StreamWriterBase, MaterializeWriterBase, # <PreviousStageOutputType> can also be found here
|
|
179
|
+
|
|
180
|
+
class CustomWriter(MaterializeWriterBase):
|
|
181
|
+
def __init__(self, ...):
|
|
182
|
+
...
|
|
183
|
+
def open(self) -> None:
|
|
184
|
+
# Opening your writer
|
|
185
|
+
|
|
186
|
+
def write(self, sample: <PreviousStageOutputType>) -> None:
|
|
187
|
+
# What to do with a single sample
|
|
188
|
+
def close(self) -> None:
|
|
189
|
+
# Closing up the buffer
|
|
190
|
+
|
|
191
|
+
def get_output(self) -> Any:
|
|
192
|
+
# Optional: if you want to output something in memory.
|
|
193
|
+
|
|
194
|
+
# StreamWriterBase is slightly simpler
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Profiling runtime of a custom component:
|
|
198
|
+
```python
|
|
199
|
+
import time
|
|
200
|
+
|
|
201
|
+
class CustomStage(Stage/WriterBase):
|
|
202
|
+
...
|
|
203
|
+
|
|
204
|
+
def __call__(self, it: ...):
|
|
205
|
+
prof = self.get_current_profiler()
|
|
206
|
+
for something in it:
|
|
207
|
+
# Start measuring the iteration
|
|
208
|
+
t0 = time.perf_counter()
|
|
209
|
+
|
|
210
|
+
# Do some heavy operation
|
|
211
|
+
output = ...
|
|
212
|
+
|
|
213
|
+
# Stop the clock
|
|
214
|
+
dt = time.perf_counter() - t0
|
|
215
|
+
if output:
|
|
216
|
+
prof.add_time("CustomStage", dt, yielded=True)
|
|
217
|
+
yield output
|
|
218
|
+
else:
|
|
219
|
+
prof.add_time("CustomStage", dt, yielded=False)
|
|
220
|
+
```
|
|
221
|
+
This will count per slide per iteration breakdown of how fast this stage is, in the form of:
|
|
222
|
+
```
|
|
223
|
+
=== Pipeline Profile (isolated timings only) ===
|
|
224
|
+
Stage Yields Wall (s) Avg (ms/yield)
|
|
225
|
+
PNGEncoder.isolated 640 1.440s 2.412ms
|
|
226
|
+
|
|
227
|
+
--- Per slide breakdown ---
|
|
228
|
+
[RBIO-GC072-HE-02]
|
|
229
|
+
PNGEncoder.isolated yields= 320 wall= 0.762s avg= 2.382ms
|
|
230
|
+
[RBIO-GC072-HE-01]
|
|
231
|
+
PNGEncoder.isolated yields= 320 wall= 0.778s avg= 2.432ms
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## 5) Development install
|
|
235
|
+
|
|
236
|
+
Python ≥3.10 is recommended. UV is also recommended as the package manager
|
|
237
|
+
```
|
|
238
|
+
git clone https://github.com/amspath/wsi-patching-pipeline.git
|
|
239
|
+
cd wsi-patching-pipeline
|
|
240
|
+
uv sync --extra dev,gpu
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
## 6) More will come
|
|
245
|
+
- [ ] Retrained MobileNet classifier for tissue detection with proper documentation.
|
|
246
|
+
- [ ] Controlled batch sizes in each of the shipped writers
|
|
247
|
+
|
|
248
|
+
## 7) Contributing
|
|
249
|
+
Feel free to contribute by opening a pull request or adding an issue to the github. We develop this library based on our own usage of it. So if something is not implemented, we just haven´t had the need for it yet. However, we are very open to add new functionality.
|