-
Notifications
You must be signed in to change notification settings - Fork 2
Added guard from colinear point error and crops with 0 area #246
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: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR fixes a pipeline-breaking issue caused by colinear points exceptions and zero-area crops in detection processing. The solution introduces robust coordinate validation and normalization to ensure all generated crops have valid dimensions and stay within frame boundaries.
- Replaces simple coordinate copying with comprehensive validation logic that handles edge cases
- Adds pixel-aware minimum dimensions to prevent zero-area crops
- Implements coordinate ordering, clamping, and padding with boundary checks
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #246 +/- ##
==========================================
+ Coverage 53.46% 55.11% +1.65%
==========================================
Files 91 91
Lines 5905 5913 +8
==========================================
+ Hits 3157 3259 +102
+ Misses 2748 2654 -94 ☔ View full report in Codecov by Sentry. |
|
Nice catch. Could you test the script with one example with the full pipeline? E.g. human-pose. Just make sure you have the dai-nodes version from your source. |
I did test it with several pipelines, mainly gaze estimation and also with the pipeline it was primarily created for: |
|
Ok, but gaze-estimation does not use |
Oh, sry I did mean human pose just messed up when was writing the message |
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.
I went over the PR and looks good. But I am wondering why do we even want to crop a bbox that has 0 area? Do we have situations where this is useful? IMHO I would either filter such detections inside the generate_script_content function or better yet filter detections beforehand to keep a clean list of all detections.
You can't really control how people will use this script node. So filtering before hand would be the "suggested" way to do it but if user doesn't filter then this script by itself shouldn't fail because of it. |
Yes I agree the node should not fail or crash the pipeline but we also dont want unexpected behaviour.
In depthai the practice is that each node should have one specific task. If it is a config creator, it should only do that and if it gets some wierd / invalid inputs, it should either error out or skip invalid input and print an informative warning saying it dropped it. The benifits of this approach are:
All in all, in this situation I would make it such that for each detection, check if valid => create config, else => skip and print warning. |
But in that case you are actually doing the filtering and there is no way to disable this behaviour (other than writing your own "script node generator" function). Following the logic of "each node should have one responsibility" I would then leave as is right now, without filtering. And if you want to filter do it with "Filter" node before this script node. |
No reason to disable the behaviour as it would just crash ImageManipNode.
I'm OK with this approach as well, but would still validate the detection and fail gracefully (eg error out with "Detection with bounding box area = 0 encountered, stopping. Please filter invalid detections beforehand." ). This might be even better as it makes it much easier to later sync the detections and the cropped images together as there is always the same number of cropped images produced per input ImgDetections message. |
…tor crash on zero-area detection
|
Made adjustments based on the discussion. New expected flow:
Downside of this approach:
Thoughts? @aljazkonec1 @kkeroo @FSAFTik @PetrNovota |
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.
Looks good, left one comment to remove the label filter from config sender script node. Also left a second comment regarding Filter node as the node works with both dai-nodes message types and dai message types, while the config sender script only works with dai message types. We need to make this explicitly clear as sending ImgDetectionsExtended to the config creator will crash the pipeline.
Regarding the downside of this approach:
The additional sending from device->host when using filter node is only true if the NN is a supported YOLO type as then the parser is already implemented on device side. If the NN is anything besides YOLO, the NN output will be sent to host (because of parser) no matter what. The additional filter node will therefore not take any additional bandwidth.
| resize_mode: str = "STRETCH", | ||
| padding: float = 0, | ||
| padding: float = 0.0, | ||
| valid_labels: Optional[List[int]] = None, |
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.
We could remove label filer in the detection config generator as Filter node already handles this and would be in line with single node - single responsibility.
| if area < self._min_area: | ||
| continue | ||
|
|
||
| filtered_detections.append(detection) |
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.
detection is of type dai.ImgDetection, nodes ImgDetectionExtended or dai.SpatialImgDetection. For a host node this is OK, but we need to be careful if using it with the config sender script as it only works with dai message types.
Purpose
Change is introduced to fix problem with Colinear points exception breaking the pipeline
Specification
Added guard form making zero area crops and edge pins
Dependencies & Potential Impact
Added changes to generate_script_content, what may influence pipelines using this script,
however it shouldn't interact with correct detections and only change the invalid ones to not break the pipeline run
Deployment Plan
None / not applicable
Testing & Validation
Tested on several pipelines using generate_script_content and different NN and didn't see any problems.
Also it was tested with manual change of detections to invalid ones and the pipeline was not breaking but continued its run