-
Notifications
You must be signed in to change notification settings - Fork 0
feat: tile masks #6
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
base: feature/tiling
Are you sure you want to change the base?
Changes from all commits
bdc0f9a
b8242f4
2c02ee2
996dbf4
752cdd7
dc136c5
282eb88
177f79b
3943872
9f67c7b
37c977f
a21c8cd
6a8d5ca
b52a14d
717c083
5737ea4
e23d84c
1355b49
d7386da
8bec2dd
ca95c2c
f5d292e
41ba4aa
e4d7dad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ftn@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.17 | ||
| tile_extent: 320 | ||
| level: 0 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/bbbe4603bc30495d85ac99093fc9269a/artifacts/train - ftn" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/bbbe4603bc30495d85ac99093fc9269a/artifacts/test preliminary - ftn" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/bbbe4603bc30495d85ac99093fc9269a/artifacts/test final - ftn" # TODO update URI | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ftn@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.17 | ||
| tile_extent: 430 | ||
| level: 0 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/de450f835f0d4462a91b35f4a79a500f/artifacts/train - ftn" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/de450f835f0d4462a91b35f4a79a500f/artifacts/test preliminary - ftn" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/de450f835f0d4462a91b35f4a79a500f/artifacts/test final - ftn" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ftn@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.52 | ||
| tile_extent: 224 | ||
| level: 1 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/f85b64a7f96c41e38f86d84956e2dbe9/artifacts/train - ftn" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/f85b64a7f96c41e38f86d84956e2dbe9/artifacts/test preliminary - ftn" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/f85b64a7f96c41e38f86d84956e2dbe9/artifacts/test final - ftn" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ftn@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 1.55 | ||
| tile_extent: 224 | ||
| level: 2 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/5814484b6cd7467e9d712889655479af/artifacts/train - ftn" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/5814484b6cd7467e9d712889655479af/artifacts/test preliminary - ftn" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/5814484b6cd7467e9d712889655479af/artifacts/test final - ftn" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ikem@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.17 | ||
| tile_extent: 320 | ||
| level: 0 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/4486e598446d412d926ac66dadb35e51/artifacts/train - ikem" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/4486e598446d412d926ac66dadb35e51/artifacts/test preliminary - ikem" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/4486e598446d412d926ac66dadb35e51/artifacts/test final - ikem" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ikem@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.17 | ||
| tile_extent: 430 | ||
| level: 0 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/fd112e63819c49d999502542b35bfce1/artifacts/train - ikem" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/fd112e63819c49d999502542b35bfce1/artifacts/test preliminary - ikem" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/fd112e63819c49d999502542b35bfce1/artifacts/test final - ikem" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ikem@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.52 | ||
| tile_extent: 224 | ||
| level: 1 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/ece822e7c0e3416f97212267c773c8ac/artifacts/train - ikem" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/ece822e7c0e3416f97212267c773c8ac/artifacts/test preliminary - ikem" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/ece822e7c0e3416f97212267c773c8ac/artifacts/test final - ikem" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/ikem@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 1.55 | ||
| tile_extent: 224 | ||
| level: 2 | ||
| tiling_uris: | ||
| train: "mlflow-artifacts:/86/0c09e1c61d294fa3877b6b21703bab2f/artifacts/train - ikem" # TODO update URI | ||
| test_preliminary: "mlflow-artifacts:/86/0c09e1c61d294fa3877b6b21703bab2f/artifacts/test preliminary - ikem" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/0c09e1c61d294fa3877b6b21703bab2f/artifacts/test final - ikem" # TODO update URI | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/knl_patos@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.17 | ||
| tile_extent: 320 | ||
| level: 0 | ||
| tiling_uris: | ||
| test_preliminary: "mlflow-artifacts:/86/7b9a446145b14965981bbac88e8e2c8b/artifacts/test preliminary - knl_patos" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/7b9a446145b14965981bbac88e8e2c8b/artifacts/test final - knl_patos" # TODO update URI | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/knl_patos@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.17 | ||
| tile_extent: 430 | ||
| level: 0 | ||
| tiling_uris: | ||
| test_preliminary: "mlflow-artifacts:/86/eb29255c944d4dad926160a7cb102ad9/artifacts/test preliminary - knl_patos" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/eb29255c944d4dad926160a7cb102ad9/artifacts/test final - knl_patos" # TODO update URI | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/knl_patos@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 0.52 | ||
| tile_extent: 224 | ||
| level: 1 | ||
| tiling_uris: | ||
| test_preliminary: "mlflow-artifacts:/86/6782155362d54ecc9f1beccb4362d359/artifacts/test preliminary - knl_patos" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/6782155362d54ecc9f1beccb4362d359/artifacts/test final - knl_patos" # TODO update URI | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| defaults: | ||
| - /dataset/processed_w_masks/knl_patos@_here_ | ||
| - _self_ | ||
|
|
||
| mpp: 1.55 | ||
| tile_extent: 224 | ||
| level: 2 | ||
| tiling_uris: | ||
| test_preliminary: "mlflow-artifacts:/86/d7486bb6b667433989c3ce1c8ce31d60/artifacts/test preliminary - knl_patos" # TODO update URI | ||
| test_final: "mlflow-artifacts:/86/d7486bb6b667433989c3ce1c8ce31d60/artifacts/test final - knl_patos" # TODO update URI | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The URIs in this configuration file contain |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # @package _global_ | ||
|
|
||
| max_concurrent: 64 | ||
| artifact_path: tile_masks | ||
| level: 3 | ||
|
|
||
| metadata: | ||
| run_name: "🎭 Tile Masks: ${dataset.institution}" | ||
| description: Tile masks for ${dataset.institution} at tiling level ${dataset.level} | ||
| hyperparams: | ||
| mask_level: ${level} | ||
| tiling_level: ${dataset.level} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,97 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from collections.abc import Iterable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from tempfile import TemporaryDirectory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import cast | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import hydra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import mlflow.artifacts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pandas as pd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pyvips | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from omegaconf import DictConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from openslide import OpenSlide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from rationai.masks import process_items, slide_resolution, tile_mask, write_big_tiff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from rationai.mlkit import autolog, with_cli_args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from rationai.mlkit.lightning.loggers import MLFlowLogger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def download_slide_tiles(uris: Iterable[str]) -> tuple[pd.DataFrame, pd.DataFrame]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slidess, tiless = [], [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for uri in uris: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path = mlflow.artifacts.download_artifacts(artifact_uri=uri) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slidess.append(pd.read_parquet(Path(path) / "slides.parquet")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tiless.append(pd.read_parquet(Path(path) / "tiles.parquet")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slides = pd.concat(slidess).reset_index(drop=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tiles = pd.concat(tiless).reset_index(drop=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable names
Suggested change
Comment on lines
+20
to
+27
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| slidess, tiless = [], [] | |
| for uri in uris: | |
| path = mlflow.artifacts.download_artifacts(artifact_uri=uri) | |
| slidess.append(pd.read_parquet(Path(path) / "slides.parquet")) | |
| tiless.append(pd.read_parquet(Path(path) / "tiles.parquet")) | |
| slides = pd.concat(slidess).reset_index(drop=True) | |
| tiles = pd.concat(tiless).reset_index(drop=True) | |
| slides_parts, tiles_parts = [], [] | |
| for uri in uris: | |
| path = mlflow.artifacts.download_artifacts(artifact_uri=uri) | |
| slides_parts.append(pd.read_parquet(Path(path) / "slides.parquet")) | |
| tiles_parts.append(pd.read_parquet(Path(path) / "tiles.parquet")) | |
| slides = pd.concat(slides_parts).reset_index(drop=True) | |
| tiles = pd.concat(tiles_parts).reset_index(drop=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory for the Ray remote function is hardcoded to 4GB. This might not be optimal for all environments. Consider defining this as a constant at the top of the file (e.g., RAY_WORKER_MEMORY = 4 * 1024**3) to make it more visible and easier to change, or making it configurable via the Hydra config.
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slide_tiles = tiles[tiles["slide_id"] == slide.id] performs a full scan of the entire tiles DataFrame for every slide. For large datasets this becomes O(#slides × #tiles) and can dominate runtime. Consider pre-indexing/grouping once (e.g., set tiles index to slide_id and use .loc[...], or build a dict[slide_id, tiles_subset] before launching Ray tasks) so each task only touches its own slide’s rows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The blur/artifacts thresholds are hard-coded as 0.25. Given that other preprocessing steps expose thresholds via Hydra config (e.g., tissue_threshold in tiling), it would be more maintainable to make these configurable (e.g., blur_threshold, artifacts_threshold in configs/preprocessing/tile_masks.yaml) so they can be tuned without code changes.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||
| from kube_jobs import storage, submit_job | ||||||
|
|
||||||
|
|
||||||
| submit_job( | ||||||
| job_name="ulcerative-colitis-tile-masks-...", | ||||||
| username=..., | ||||||
| public=False, | ||||||
| cpu=64, | ||||||
| memory="32Gi", | ||||||
| script=[ | ||||||
| "git clone https://github.com/RationAI/ulcerative-colitis.git workdir", | ||||||
| "cd workdir", | ||||||
| "uv sync --frozen", | ||||||
| "uv run --active -m preprocessing.tile_masks +dataset=tiled/.../...", | ||||||
| ], | ||||||
| storage=[storage.secure.Data], | ||||||
|
||||||
| storage=[storage.secure.Data], | |
| storage=[storage.secure.DATA], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script appears to be a template and is not runnable in its current state. It contains placeholder values such as ... for job_name and username, and an incomplete dataset path. These placeholders must be replaced with actual values before this can be used. Committing template files can lead to confusion and errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URIs in this configuration file contain
TODO update URIcomments, indicating they are placeholders. These should be updated with the correct values before merging to ensure the configuration is complete and functional. Additionally, the file is missing a final newline character, which is a standard convention for text files and can prevent issues with some tools.