-
Notifications
You must be signed in to change notification settings - Fork 0
feat: tissue masks #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6e1d4b9
chore: replace pdm with uv
Adames4 d7a1ef3
feat: configs
Adames4 34abac4
feat: dataset creation
Adames4 80eca85
fix: configs
Adames4 97335ef
fix: configs
Adames4 727c729
feat: add scripts
Adames4 fa9f581
fix: invalid job name
Adames4 fd978b3
fix: set slide_id as index and ensure nancy is an integer
Adames4 2869916
chore: dependencies
Adames4 725e17d
feat: processed data
Adames4 f7026b3
feat: tissue masks
Adames4 ed49c42
feat: script
Adames4 87113e1
feat: script
Adames4 de98fef
fix: job name
Adames4 929d298
fix: exclude .git folder from ray env
Adames4 81d4df3
fix: exclude .venv folder from ray env
Adames4 3f0321f
fix: typo
Adames4 2ecde13
feat: job script
Adames4 6cae5d0
feat: config
Adames4 616ed48
feat: job script
Adames4 bd0c6ac
fix: PR comments
Adames4 9ffea96
chore: dependencies
Adames4 0db7d08
chore: Merge branch 'feature/dataset' into feature/tissue-masks
Adames4 b833059
feat: refactor configs
Adames4 3300341
fix: PR comments
Adames4 e7a4dfa
chore: Merge branch 'master' into feature/tissue-masks
Adames4 76196ef
fix: typo
Adames4 6bf43f1
feat: update dataset uris
Adames4 978ceee
fix: PR
Adames4 003d93b
chore: mypy
Adames4 c13ee1a
feat: with ray init
Adames4 e7b5a87
feat: script
Adames4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| defaults: | ||
| - /dataset/raw/ftn@_here_ | ||
| - _self_ | ||
|
|
||
| uri: mlflow-artifacts:/86/d2b2f1835fc647e2ba3639ce606f4768/artifacts/dataset.csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| defaults: | ||
| - /dataset/raw/ikem@_here_ | ||
| - _self_ | ||
|
|
||
| uri: mlflow-artifacts:/86/7c6e7cc142494d45b6513185318d4462/artifacts/dataset.csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| defaults: | ||
| - /dataset/raw/knl_patos@_here_ | ||
| - _self_ | ||
|
|
||
| uri: mlflow-artifacts:/86/f690f64ded624da9a7150a7a92385aec/artifacts/dataset.csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # @package _global_ | ||
|
|
||
| level: 3 | ||
| max_concurrent: 64 | ||
| artifact_path: tissue_masks | ||
|
|
||
| metadata: | ||
| run_name: "🎭 Tissue Masks: ${dataset.institution}" | ||
| description: Tissue masks for ${dataset.institution} at level ${level} | ||
| hyperparams: | ||
| level: ${level} |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from pathlib import Path | ||
vejtek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from tempfile import TemporaryDirectory | ||
| from typing import cast | ||
|
|
||
| import hydra | ||
| import pandas as pd | ||
| import pyvips | ||
| import ray | ||
| from mlflow.artifacts import download_artifacts | ||
| from omegaconf import DictConfig | ||
| from openslide import OpenSlide | ||
| from rationai.masks import ( | ||
| process_items, | ||
| slide_resolution, | ||
| tissue_mask, | ||
| write_big_tiff, | ||
| ) | ||
| from rationai.mlkit import autolog, with_cli_args | ||
| from rationai.mlkit.lightning.loggers import MLFlowLogger | ||
|
|
||
|
|
||
| @ray.remote(memory=4 * 1024**3) | ||
Adames4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def process_slide(slide_path: str, level: int, output_path: Path) -> None: | ||
| with OpenSlide(slide_path) as slide: | ||
| mpp_x, mpp_y = slide_resolution(slide, level) | ||
|
|
||
| image = cast("pyvips.Image", pyvips.Image.new_from_file(slide_path, level=level)) | ||
| mask = tissue_mask(image, mpp=(mpp_x + mpp_y) / 2) | ||
| mask_path = output_path / Path(slide_path).with_suffix(".tiff").name | ||
Adames4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| write_big_tiff(mask, path=mask_path, mpp_x=mpp_x, mpp_y=mpp_y) | ||
|
|
||
|
|
||
| @with_cli_args(["+preprocessing=tissue_masks"]) | ||
| @hydra.main(config_path="../configs", config_name="preprocessing", version_base=None) | ||
| @autolog | ||
| def main(config: DictConfig, logger: MLFlowLogger) -> None: | ||
| dataset = pd.read_csv(download_artifacts(config.dataset.uri)) | ||
|
|
||
vejtek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with TemporaryDirectory() as output_dir: | ||
| process_items( | ||
| dataset["path"], | ||
| process_item=process_slide, | ||
| fn_kwargs={ | ||
| "level": config.level, | ||
| "output_path": Path(output_dir), | ||
| }, | ||
| max_concurrent=config.max_concurrent, | ||
| ) | ||
vejtek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| logger.log_artifacts(local_dir=output_dir, artifact_path=config.artifact_path) | ||
Adames4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| with ray.init(runtime_env={"excludes": [".git", ".venv"]}): | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from kube_jobs import storage, submit_job | ||
|
|
||
|
|
||
| submit_job( | ||
| job_name="ulcerative-colitis-tissue-masks-...", | ||
| username=..., | ||
| public=False, | ||
| cpu=64, | ||
| memory="32Gi", | ||
| shm="16Gi", | ||
| script=[ | ||
| "git clone https://github.com/RationAI/ulcerative-colitis.git workdir", | ||
| "cd workdir", | ||
| "uv sync --frozen", | ||
| "uv run --active -m preprocessing.tissue_masks +dataset=processed/...", | ||
vejtek marked this conversation as resolved.
Show resolved
Hide resolved
Adames4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ], | ||
| storage=[storage.secure.DATA], | ||
Adames4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
Adames4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.