Skip to content

✨ Define SemanticSegmentor with the New EngineABC #866

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

Draft
wants to merge 89 commits into
base: dev-define-engines-abc
Choose a base branch
from

Conversation

shaneahmed
Copy link
Member

  • Define SemanticSegmentor with the New EngineABC

@shaneahmed shaneahmed self-assigned this Sep 20, 2024
@shaneahmed shaneahmed added the enhancement New feature or request label Sep 20, 2024
@shaneahmed shaneahmed added this to the Release v2.0.0 milestone Sep 20, 2024
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.86%. Comparing base (f7abbe8) to head (2b790b8).

Additional details and impacted files
@@                    Coverage Diff                     @@
##           dev-define-engines-abc     #866      +/-   ##
==========================================================
+ Coverage                   91.77%   91.86%   +0.08%     
==========================================================
  Files                          73       74       +1     
  Lines                        9345     9436      +91     
  Branches                     1222     1234      +12     
==========================================================
+ Hits                         8576     8668      +92     
  Misses                        756      756              
+ Partials                       13       12       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@shaneahmed shaneahmed marked this pull request as draft February 5, 2025 16:27
- Use `input_resolutions` instead of resolution to make engines outputs compatible with ioconfig.
- Uses input resolution as a list of dictionaries on units and resolution.
- Use `input_resolutions` instead of resolution to make engines outputs compatible with ioconfig.
- Uses input resolution as a list of dictionaries on units and resolution.
…mentor

# Conflicts:
#	tests/engines/test_engine_abc.py
#	tests/engines/test_patch_predictor.py
#	tiatoolbox/models/engine/engine_abc.py
#	tiatoolbox/models/engine/io_config.py
#	tiatoolbox/models/engine/patch_predictor.py
shaneahmed added a commit that referenced this pull request May 9, 2025
…929)

- This PR saves a NumPy or Zarr Array to OME tiff. This will help to save probability maps from deep learning models as ome.tiff which can be visualized using TIAViz.
- The image is written as tiles and stitched in OME tiff along with associated necessary metadata for heatmaps generated by segmentation engine.  #866 
- Reading with QuPath and TIAViz has been tested.
@Jiaqi-Lv Jiaqi-Lv requested a review from Copilot May 23, 2025 09:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates a new EngineABC into the library by defining SemanticSegmentor and refactors related utilities to support patch-based segmentation consistently.

  • Renames and refactors dict_to_storedict_to_store_patch_predictions and updates looping logic in dict_to_zarr
  • Adds patch_input_shape validation in PatchDataset via a new DimensionMismatchError
  • Introduces argmax_last_axis util and replaces inline post-processing in UNet/vanilla architectures
  • Updates tests and sample data to exercise the new SemanticSegmentor and shape checks

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tiatoolbox/utils/transforms.py Expanded imresize interpolation type to accept int or str.
tiatoolbox/utils/misc.py Renamed dict_to_store, refactored dict_to_zarr to loop keys.
tiatoolbox/utils/exceptions.py Added DimensionMismatchError for shape mismatches.
tiatoolbox/models/engine/engine_abc.py Updated calls to new store function, propagate ioconfig.
tiatoolbox/models/dataset/dataset_abc.py Added patch_input_shape param and runtime shape check.
tiatoolbox/models/architecture/utils.py New argmax_last_axis util.
tiatoolbox/models/architecture/vanilla.py Replaced inline postproc with argmax_last_axis.
tiatoolbox/models/architecture/unet.py Switched batch output to dict, added pad and postproc method.
tiatoolbox/data/remote_samples.yaml Added a new thumbnail sample.
tests/ Updated tests to use new functions, added dimension-mismatch tests.
Comments suppressed due to low confidence (3)

tiatoolbox/utils/misc.py:1643

  • Within the loop you cast raw_predictions[key] to array but then pass the original value. You should pass array to the data parameter to ensure the dataset uses the NumPy array with the correct shape.
z.create_dataset(name=key, data=value, compression=compressor, shape=array.shape,)

tiatoolbox/utils/transforms.py:97

  • [nitpick] The signature now allows interpolation to be an int or str. Please update the function docstring to reflect that both types are accepted.
output_size: int | tuple[int, int] | None = None,

tests/test_utils.py:1650

  • Add a test to verify that dict_to_zarr correctly creates all datasets for each key in raw_predictions, including optional chunks parameters if those are expected.
# test dict_to_zarr with multiple keys

@@ -609,6 +617,18 @@ def __getitem__(self: PatchDataset, idx: int) -> dict:
if not self.data_is_npy_alike:
patch = self.load_img(patch)

if patch.shape[:-1] != tuple(self.patch_input_shape):
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If patch_input_shape is None, calling tuple(self.patch_input_shape) will raise a TypeError. Consider validating or requiring patch_input_shape in the constructor and raising a clear error if not provided.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants