Skip to content

CodeRabbitAI suggested fixes + miscellaneous fixes#305

Merged
klemen1999 merged 24 commits into
mainfrom
feat/misc-fixes
Jul 16, 2026
Merged

CodeRabbitAI suggested fixes + miscellaneous fixes#305
klemen1999 merged 24 commits into
mainfrom
feat/misc-fixes

Conversation

@dtronmans

@dtronmans dtronmans commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Purpose

In a previous PR #302 CodeRabbit suggested some fixes that were unrelated to the refactor of this PR. In this PR, these fixes are addressed one-by-one.

Summary of suggested changes covered by this PR:

Non-CodeRabbit suggestion: this PR also implements this suggestion from LuxonisML

Specification

None / not applicable

Dependencies & Potential Impact

None / not applicable

Deployment Plan

None / not applicable

Testing & Validation

None / not applicable

AI Usage

Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Submitted code was reviewed by a human: YES/NO

The author is taking the responsibility for the contribution: YES/NO

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved FastSAM segmentation mask counting and logging, including correct handling when no masks are detected.
    • Updated NMS processing for more reliable bounding-box results.
    • Refined image and map output dimension handling for singleton batch cases, with clearer validation errors for unexpected shapes.
    • Improved cached anchor refreshing when SCRFD configuration changes.
    • Enhanced segmentation class-count reporting across model configurations.
    • Added validation for mismatched YOLO stride settings and improved instance-mask limit messaging.

@dtronmans
dtronmans marked this pull request as draft July 10, 2026 12:47
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 507ccb41-ad08-4808-9438-90592421128f

📥 Commits

Reviewing files that changed from the base of the PR and between 802ac04 and bfa49c5.

📒 Files selected for processing (1)
  • depthai_nodes/node/parsers/utils/map_output.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • depthai_nodes/node/parsers/utils/map_output.py

📝 Walkthrough

Walkthrough

FastSAM now propagates mask counts explicitly. SCRFD refreshes cached anchors after configuration changes. Segmentation logging uses configured or inferred class counts, and parser utilities add input normalization and validation.

Changes

Parser updates

Layer / File(s) Summary
FastSAM mask-count contract
depthai_nodes/node/parsers/fastsam.py, depthai_nodes/node/parsers/utils/fastsam.py
FastSAM computation returns merged masks with an explicit count, which run() passes to emit() for logging.
SCRFD anchor cache refresh
depthai_nodes/node/parsers/scrfd.py
Anchor caching is centralized and refreshed when input size, feature strides, anchor count, or build configuration changes.
Segmentation class-count logging
depthai_nodes/node/parsers/segmentation.py
Class metadata is loaded from configuration, and emitted class counts use configured or inferred values.
Parser output and detection validation
depthai_nodes/node/parsers/utils/detection.py, depthai_nodes/node/parsers/utils/image_output.py, depthai_nodes/node/parsers/utils/map_output.py, depthai_nodes/node/parsers/utils/yolo.py
Detection boxes and indices are normalized, image and map dimensions are validated, YOLO stride counts are checked, and overflow errors use the computed limit.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • luxonis/depthai-nodes#302: Refactors the FastSAM extract/compute/emit pipeline that this change extends with explicit mask-count propagation.

Suggested reviewers: tersekmatija, klemen1999

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is related to the patch, but it is too vague and generic to convey the main change clearly. Use a concise title that names the primary area changed, such as FastSAM/SCRFD/parser fixes or updated output handling.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/misc-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Base automatically changed from feat/extract-compute-emit to main July 15, 2026 10:18
@codecov-commenter

codecov-commenter commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 7.89474% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.16%. Comparing base (592c324) to head (bfa49c5).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
depthai_nodes/node/parsers/segmentation.py 8.33% 11 Missing ⚠️
depthai_nodes/node/parsers/scrfd.py 14.28% 6 Missing ⚠️
depthai_nodes/node/parsers/utils/map_output.py 0.00% 6 Missing ⚠️
depthai_nodes/node/parsers/fastsam.py 25.00% 3 Missing ⚠️
depthai_nodes/node/parsers/utils/detection.py 0.00% 3 Missing ⚠️
depthai_nodes/node/parsers/utils/fastsam.py 0.00% 3 Missing ⚠️
depthai_nodes/node/parsers/utils/yolo.py 0.00% 2 Missing ⚠️
depthai_nodes/node/parsers/utils/image_output.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #305      +/-   ##
==========================================
- Coverage   48.28%   48.16%   -0.13%     
==========================================
  Files         110      110              
  Lines        6753     6783      +30     
==========================================
+ Hits         3261     3267       +6     
- Misses       3492     3516      +24     

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

@dtronmans
dtronmans marked this pull request as ready for review July 15, 2026 12:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
depthai_nodes/node/parsers/utils/fastsam.py (1)

410-411: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression tests for the new mask-count contract.

Please cover empty results (0), normal detections, and bbox/point prompts. These tests should assert both the returned tuple and the count forwarded to the parser, especially given the reported low patch coverage.

Also applies to: 465-469

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@depthai_nodes/node/parsers/utils/fastsam.py` around lines 410 - 411, Add
regression tests around the FastSAM output-decoding function returning the
mask/count tuple, covering empty results, normal detections, and both bbox and
point prompts. Assert the complete returned tuple and verify the corresponding
mask count forwarded to the parser, using mocks or fixtures for the parser
interaction.
depthai_nodes/node/parsers/segmentation.py (1)

212-212: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Prevent expensive np.unique evaluation when debug logging is disabled.

Because f-strings are evaluated before the method is called, _get_logged_class_count will execute on every frame. If class_names and n_classes are not configured, this falls back to np.unique on the entire segmentation mask, which can introduce noticeable CPU overhead (e.g., filtering and sorting a large flattened array) even when debug logs are turned off.

Consider wrapping this statement to check the log level first.

⚡ Proposed performance optimization
-        self._logger.debug(
-            f"Created segmentation message with {self._get_logged_class_count(class_map)} classes"
-        )
+        if self._logger.isEnabledFor(logging.DEBUG):
+            self._logger.debug(
+                f"Created segmentation message with {self._get_logged_class_count(class_map)} classes"
+            )

(Note: Ensure import logging is present at the top of the file if applying this change.)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@depthai_nodes/node/parsers/segmentation.py` at line 212, Guard the “Created
segmentation message” debug log with a DEBUG-level check before interpolating
`_get_logged_class_count`, preventing its potentially expensive `np.unique`
fallback when debug logging is disabled. Add the `logging` import if needed and
preserve the existing message and count behavior when debug logging is enabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@depthai_nodes/node/parsers/utils/yolo.py`:
- Around line 707-708: Update the YOLO segmentation error message to report the
number of encodable instance masks as max_instance_id + 1, matching the
validation check’s zero-based ID range; keep the surrounding SegmentationMask
handling unchanged.

---

Nitpick comments:
In `@depthai_nodes/node/parsers/segmentation.py`:
- Line 212: Guard the “Created segmentation message” debug log with a
DEBUG-level check before interpolating `_get_logged_class_count`, preventing its
potentially expensive `np.unique` fallback when debug logging is disabled. Add
the `logging` import if needed and preserve the existing message and count
behavior when debug logging is enabled.

In `@depthai_nodes/node/parsers/utils/fastsam.py`:
- Around line 410-411: Add regression tests around the FastSAM output-decoding
function returning the mask/count tuple, covering empty results, normal
detections, and both bbox and point prompts. Assert the complete returned tuple
and verify the corresponding mask count forwarded to the parser, using mocks or
fixtures for the parser interaction.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be2a9a69-7fa4-4fc1-8c2b-a4782ed8398c

📥 Commits

Reviewing files that changed from the base of the PR and between 592c324 and f7230af.

📒 Files selected for processing (8)
  • depthai_nodes/node/parsers/fastsam.py
  • depthai_nodes/node/parsers/scrfd.py
  • depthai_nodes/node/parsers/segmentation.py
  • depthai_nodes/node/parsers/utils/detection.py
  • depthai_nodes/node/parsers/utils/fastsam.py
  • depthai_nodes/node/parsers/utils/image_output.py
  • depthai_nodes/node/parsers/utils/map_output.py
  • depthai_nodes/node/parsers/utils/yolo.py

Comment thread depthai_nodes/node/parsers/utils/yolo.py Outdated
Comment thread depthai_nodes/node/parsers/utils/detection.py

@klemen1999 klemen1999 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One potential improvement, otherwise LGTM

Comment thread depthai_nodes/node/parsers/utils/map_output.py Outdated
@klemen1999
klemen1999 merged commit 5c1b746 into main Jul 16, 2026
15 of 23 checks passed
@klemen1999
klemen1999 deleted the feat/misc-fixes branch July 16, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fix Fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants