-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/tiling shm #7
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: master
Are you sure you want to change the base?
Changes from all commits
445203d
240c4bf
05fda03
8f8efd0
0230d97
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 |
|---|---|---|
|
|
@@ -23,10 +23,14 @@ | |
| from shapely.geometry import box | ||
| from shapely.geometry.polygon import Polygon | ||
|
|
||
|
|
||
| BATCH_SIZE = 256 | ||
|
|
||
|
|
||
| def add_missing_epithelium_overlap(batch: DataBatch) -> DataBatch: | ||
| batch["epithelium_overlap"] = np.nan | ||
| return batch | ||
|
|
||
|
|
||
| def add_tile_overlap( | ||
| tiles: Dataset, | ||
| roi: Polygon, | ||
|
|
@@ -78,7 +82,7 @@ def add_tile_overlap( | |
| col("mpp_y"), | ||
| ) | ||
| tiles = tiles.with_column( | ||
| overlap_struct_col, overlap_struct, num_cpus=1, memory=BATCH_SIZE * 8 * 512**2 | ||
| overlap_struct_col, overlap_struct, num_cpus=0.2, memory=512 * 1024**2 | ||
| ) | ||
|
|
||
| def extract_value(batch: DataBatch) -> DataBatch: | ||
|
|
@@ -93,8 +97,8 @@ def extract_value(batch: DataBatch) -> DataBatch: | |
| tiles = tiles.map_batches( | ||
| extract_value, | ||
| batch_format="pandas", | ||
| num_cpus=1, | ||
| memory=BATCH_SIZE * 8 * 512**2, | ||
| num_cpus=0.1, | ||
| memory=256 * 1024**2, | ||
| ) | ||
|
|
||
| return tiles.drop_columns([overlap_struct_col]) | ||
|
|
@@ -204,7 +208,12 @@ def main(config: DictConfig, logger: MLFlowLogger) -> None: | |
| ) | ||
|
|
||
| # Create unique slide IDs and save slide metadata | ||
| slides = slides.map(row_hash, num_cpus=0.1, memory=128 * 1024**2) | ||
| slides = slides.map(row_hash, num_cpus=0.1, memory=256 * 1024**2) | ||
|
|
||
| # Materialize slides so the source pipeline (read + join + hash) runs once | ||
| # and is reused for both slides_df and the tiles pipeline. | ||
| slides = slides.materialize() | ||
| slides_df = slides.to_pandas() | ||
|
|
||
| # Expand slides into tile coordinates | ||
| tiles = slides.flat_map( | ||
|
|
@@ -215,8 +224,8 @@ def main(config: DictConfig, logger: MLFlowLogger) -> None: | |
| epithelium_masks_path=epithelium_masks_path, | ||
| ), | ||
| num_cpus=0.2, | ||
| memory=BATCH_SIZE * 1024**2, | ||
| ).repartition(target_num_rows_per_block=BATCH_SIZE) | ||
| memory=256 * 1024**2, | ||
| ).repartition(target_num_rows_per_block=4096) | ||
|
|
||
| # Compute masks and filter tissue tiles | ||
| # Tissue mask checks center 50% | ||
|
|
@@ -231,16 +240,35 @@ def main(config: DictConfig, logger: MLFlowLogger) -> None: | |
| tiles, tissue_roi, "tissue_mask_path", "tissue_overlap", "0" | ||
| ) | ||
| tiles = tiles.filter(expr=col("tissue_overlap") > 0.0) | ||
|
|
||
| # Materialize after tissue filter to: | ||
| # 1. Lock in the reduction (discard background tiles before computing remaining overlaps) | ||
| # 2. Break the long operator chain to prevent streaming backpressure starvation | ||
| tiles = tiles.materialize() | ||
|
|
||
| tiles = add_tile_overlap(tiles, full_roi, "blur_mask_path", "blur_overlap", "255") | ||
| tiles = add_tile_overlap( | ||
| tiles, full_roi, "folding_mask_path", "folding_overlap", "255" | ||
| ) | ||
| tiles = add_tile_overlap( | ||
| tiles, full_roi, "residual_mask_path", "residual_overlap", "0" | ||
| ) | ||
| tiles = add_tile_overlap( | ||
| tiles, full_roi, "epithelium_mask_path", "epithelium_overlap", "0" | ||
| ) | ||
| if epithelium_masks_path: | ||
| print("[INFO] Computing overlap: epithelium_overlap from epithelium_mask_path") | ||
| tiles = add_tile_overlap( | ||
| tiles, full_roi, "epithelium_mask_path", "epithelium_overlap", "0" | ||
| ) | ||
| else: | ||
| print( | ||
| "[INFO] Skipping epithelium overlap: dataset.mlflow_uris.epithelium_masks is not set" | ||
| ) | ||
|
|
||
| tiles = tiles.map_batches( | ||
| add_missing_epithelium_overlap, | ||
| batch_format="pandas", | ||
| num_cpus=0.1, | ||
| memory=256 * 1024**2, | ||
| ) | ||
|
Comment on lines
+266
to
+271
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. Using You can replace this tiles = tiles.add_column("epithelium_overlap", lambda df: np.nan)This change would make the code more concise and performant. tiles = tiles.add_column("epithelium_overlap", lambda df: np.nan) |
||
|
|
||
| # Drop unnecessary columns | ||
| tiles = tiles.drop_columns( | ||
|
|
@@ -255,8 +283,7 @@ def main(config: DictConfig, logger: MLFlowLogger) -> None: | |
| ] | ||
| ) | ||
|
|
||
| # Convert Ray Datasets to pandas DataFrames | ||
| slides_df = slides.to_pandas() | ||
| # Convert tiles Ray Dataset to pandas DataFrame | ||
| tiles_df = tiles.to_pandas() | ||
|
|
||
| save_mlflow_dataset( | ||
|
|
||
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.
For better logging practices and consistency, it's recommended to use the
loggingmodule instead ofprintfor informational messages. This allows for more flexible log level management and redirection.You would need to add
import loggingat the top of the file. Then you can change theprintstatements tologging.info(...).