Skip to content

fix(tilers): allow skipping expensive per-tile saliency map merge - #639

Closed
A-Artemis wants to merge 1 commit into
masterfrom
aurelien/fix-tiler
Closed

fix(tilers): allow skipping expensive per-tile saliency map merge#639
A-Artemis wants to merge 1 commit into
masterfrom
aurelien/fix-tiler

Conversation

@A-Artemis

Copy link
Copy Markdown
Contributor

DetectionTiler._merge_saliency_maps merges per-tile saliency maps with a pure-Python, pixel-by-pixel nested loop (cost O(num_tiles * num_classes * H * W)). With the default tiling configuration (tile_size=400, tiles_overlap=0.5), a single large image can be split into hundreds of tiles, making that merge take minutes to hours for callers that never use the merged saliency map (e.g. when only computing detection accuracy metrics rather than an explanation).

Add a merge_saliency_maps: bool = True constructor parameter/attribute to the base Tiler class (inherited by DetectionTiler and InstanceSegmentationTiler). When set to False, the expensive per-tile saliency merge is skipped entirely. It is a plain mutable attribute so callers can toggle it at any time, not just at construction. Defaults to True, preserving existing behavior.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

DetectionTiler._merge_saliency_maps merges per-tile saliency maps with a pure-Python, pixel-by-pixel nested loop (cost O(num_tiles * num_classes * H * W)). With the default tiling configuration (tile_size=400, tiles_overlap=0.5), a single large image can be split into hundreds of tiles, making that merge take minutes to hours for callers that never use the merged saliency map (e.g. when only computing detection accuracy metrics rather than an explanation).

Add a merge_saliency_maps: bool = True constructor parameter/attribute to the base Tiler class (inherited by DetectionTiler and InstanceSegmentationTiler). When set to False, the expensive per-tile saliency merge is skipped entirely. It is a plain mutable attribute so callers can toggle it at any time, not just at construction. Defaults to True, preserving existing behavior.
@A-Artemis
A-Artemis requested a lite review from Copilot August 5, 2026 14:48
@github-actions github-actions Bot added tests Related to tests python python related changes labels Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds a merge_saliency_maps: bool = True constructor parameter/attribute to the tiler base class and threads it through detection and instance-segmentation tilers so callers can skip the expensive per-tile saliency-map merge when it’s not needed.

Changes:

  • Add merge_saliency_maps to Tiler and propagate it through DetectionTiler and InstanceSegmentationTiler.
  • Gate saliency-map merging in _merge_results for detection and instance segmentation based on self.merge_saliency_maps.
  • Add/extend unit tests to validate the new flag’s default and configurability (including an instance-segmentation skip test).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
model_api/src/model_api/tilers/tiler.py Adds merge_saliency_maps to the base tiler and documents the performance motivation.
model_api/src/model_api/tilers/detection.py Threads the flag into DetectionTiler and gates saliency merging in _merge_results.
model_api/src/model_api/tilers/instance_segmentation.py Threads the flag into InstanceSegmentationTiler and skips saliency merging when disabled.
model_api/tests/unit/tilers/test_tiler.py Adds base-tiler tests for the new attribute default, constructor behavior, and mutability.
model_api/tests/unit/tilers/test_detection_tiler.py Extends init tests to cover the new flag.
model_api/tests/unit/tilers/test_instance_segmentation_tiler.py Extends init tests and adds coverage ensuring saliency merge is skipped when disabled.
Suppressed comments (3)

model_api/src/model_api/tilers/instance_segmentation.py:35

  • This docstring says "semantic segmentation" but this class is for instance segmentation.
        """Constructor for creating a semantic segmentation tiling pipeline

model_api/src/model_api/tilers/detection.py:120

  • There’s no unit test ensuring _merge_saliency_maps is skipped when merge_saliency_maps=False for DetectionTiler (only init is tested). Since this change is specifically a performance optimization, a regression test would help prevent accidentally reintroducing the expensive merge call.
        saliency_map = (
            self._merge_saliency_maps(saliency_maps, shape, tiles_coords)
            if saliency_maps and self.merge_saliency_maps
            else np.ndarray(0)
        )

model_api/src/model_api/tilers/tiler.py:51

  • configuration: dict = {} is a shared mutable default. Prefer None + normalization to avoid accidental cross-instance state sharing (and to keep the constructor safe if config handling ever starts mutating the dict).
    def __init__(
        self,
        model,
        configuration: dict = {},
        execution_mode: str = "async",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread model_api/src/model_api/tilers/detection.py
Comment thread model_api/src/model_api/tilers/instance_segmentation.py
Comment thread model_api/src/model_api/tilers/tiler.py
Comment thread model_api/src/model_api/tilers/detection.py
@A-Artemis A-Artemis closed this Aug 6, 2026
@A-Artemis
A-Artemis deleted the aurelien/fix-tiler branch August 6, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python python related changes tests Related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants