From ae869884f88779aca055fdcfbc30cbac0ec36370 Mon Sep 17 00:00:00 2001 From: aljazkonec1 Date: Thu, 9 Jan 2025 18:48:26 +0100 Subject: [PATCH] added sequence numbers to messages --- depthai_nodes/ml/messages/creators/classification.py | 4 +++- depthai_nodes/ml/parsers/classification.py | 1 + depthai_nodes/ml/parsers/classification_sequence.py | 1 + depthai_nodes/ml/parsers/embeddings.py | 1 + depthai_nodes/ml/parsers/fastsam.py | 2 ++ depthai_nodes/ml/parsers/hrnet.py | 1 + depthai_nodes/ml/parsers/image_output.py | 1 + depthai_nodes/ml/parsers/keypoints.py | 1 + depthai_nodes/ml/parsers/lane_detection.py | 1 + depthai_nodes/ml/parsers/map_output.py | 1 + depthai_nodes/ml/parsers/mediapipe_palm_detection.py | 1 + depthai_nodes/ml/parsers/mlsd.py | 1 + depthai_nodes/ml/parsers/ppdet.py | 1 + depthai_nodes/ml/parsers/regression.py | 1 + depthai_nodes/ml/parsers/scrfd.py | 1 + depthai_nodes/ml/parsers/segmentation.py | 1 + depthai_nodes/ml/parsers/superanimal_landmarker.py | 1 + depthai_nodes/ml/parsers/utils/ppdet.py | 4 ++-- depthai_nodes/ml/parsers/xfeat.py | 11 +++++++++++ depthai_nodes/ml/parsers/yolo.py | 1 + depthai_nodes/ml/parsers/yunet.py | 1 + 21 files changed, 35 insertions(+), 3 deletions(-) diff --git a/depthai_nodes/ml/messages/creators/classification.py b/depthai_nodes/ml/messages/creators/classification.py index 780e6468..1cf0285a 100644 --- a/depthai_nodes/ml/messages/creators/classification.py +++ b/depthai_nodes/ml/messages/creators/classification.py @@ -136,7 +136,9 @@ def create_classification_sequence_message( raise ValueError("Scores should be in the range [0, 1].") if np.any(~np.isclose(scores.sum(axis=1), 1.0, atol=1e-2)): - raise ValueError("Each row of scores should sum to 1.") + raise ValueError( + f"Each row of scores should sum to 1, got {scores.sum(axis=1)}." + ) scores = scores.astype(np.float32) diff --git a/depthai_nodes/ml/parsers/classification.py b/depthai_nodes/ml/parsers/classification.py index 916af2f9..66221402 100644 --- a/depthai_nodes/ml/parsers/classification.py +++ b/depthai_nodes/ml/parsers/classification.py @@ -143,5 +143,6 @@ def run(self): msg = create_classification_message(self.classes, scores) msg.transformation = output.getTransformation() msg.setTimestamp(output.getTimestamp()) + msg.setSequenceNum(output.getSequenceNum()) self.out.send(msg) diff --git a/depthai_nodes/ml/parsers/classification_sequence.py b/depthai_nodes/ml/parsers/classification_sequence.py index a325f222..cdf3d4fe 100644 --- a/depthai_nodes/ml/parsers/classification_sequence.py +++ b/depthai_nodes/ml/parsers/classification_sequence.py @@ -180,5 +180,6 @@ def run(self): ) msg.transformation = output.getTransformation() msg.setTimestamp(output.getTimestamp()) + msg.setSequenceNum(output.getSequenceNum()) self.out.send(msg) diff --git a/depthai_nodes/ml/parsers/embeddings.py b/depthai_nodes/ml/parsers/embeddings.py index 9157cffc..53a8b211 100644 --- a/depthai_nodes/ml/parsers/embeddings.py +++ b/depthai_nodes/ml/parsers/embeddings.py @@ -64,5 +64,6 @@ def run(self): assert ( len(output_names) == 1 ), "Embeddings head should have only one output layer" + output.setSequenceNum(output.getSequenceNum()) self.out.send(output) diff --git a/depthai_nodes/ml/parsers/fastsam.py b/depthai_nodes/ml/parsers/fastsam.py index b3e35c20..1b7bab0c 100644 --- a/depthai_nodes/ml/parsers/fastsam.py +++ b/depthai_nodes/ml/parsers/fastsam.py @@ -355,4 +355,6 @@ def run(self): segmentation_message = create_segmentation_message(results_masks) segmentation_message.transformation = output.getTransformation() segmentation_message.setTimestamp(output.getTimestamp()) + segmentation_message.setSequenceNum(output.getSequenceNum()) + self.out.send(segmentation_message) diff --git a/depthai_nodes/ml/parsers/hrnet.py b/depthai_nodes/ml/parsers/hrnet.py index 3626ef2a..dfc53e74 100644 --- a/depthai_nodes/ml/parsers/hrnet.py +++ b/depthai_nodes/ml/parsers/hrnet.py @@ -114,5 +114,6 @@ def run(self): ) keypoints_message.setTimestamp(output.getTimestamp()) keypoints_message.transformation = output.getTransformation() + keypoints_message.setSequenceNum(output.getSequenceNum()) self.out.send(keypoints_message) diff --git a/depthai_nodes/ml/parsers/image_output.py b/depthai_nodes/ml/parsers/image_output.py index 66f86237..80086ac9 100644 --- a/depthai_nodes/ml/parsers/image_output.py +++ b/depthai_nodes/ml/parsers/image_output.py @@ -115,5 +115,6 @@ def run(self): image_message.setTimestamp(output.getTimestamp()) if output.getTransformation(): image_message.setTransformation(output.getTransformation()) + image_message.setSequenceNum(output.getSequenceNum()) self.out.send(image_message) diff --git a/depthai_nodes/ml/parsers/keypoints.py b/depthai_nodes/ml/parsers/keypoints.py index ce76fb16..254a96ba 100644 --- a/depthai_nodes/ml/parsers/keypoints.py +++ b/depthai_nodes/ml/parsers/keypoints.py @@ -173,5 +173,6 @@ def run(self): msg = create_keypoints_message(keypoints) msg.setTimestamp(output.getTimestamp()) msg.transformation = output.getTransformation() + msg.setSequenceNum(output.getSequenceNum()) self.out.send(msg) diff --git a/depthai_nodes/ml/parsers/lane_detection.py b/depthai_nodes/ml/parsers/lane_detection.py index b51246b3..7faa5364 100644 --- a/depthai_nodes/ml/parsers/lane_detection.py +++ b/depthai_nodes/ml/parsers/lane_detection.py @@ -204,5 +204,6 @@ def run(self): msg = create_cluster_message(points) msg.setTimestamp(output.getTimestamp()) msg.transformation = output.getTransformation() + msg.setSequenceNum(output.getSequenceNum()) self.out.send(msg) diff --git a/depthai_nodes/ml/parsers/map_output.py b/depthai_nodes/ml/parsers/map_output.py index 8de18f56..b0eb12b8 100644 --- a/depthai_nodes/ml/parsers/map_output.py +++ b/depthai_nodes/ml/parsers/map_output.py @@ -107,5 +107,6 @@ def run(self): ) map_message.setTimestamp(output.getTimestamp()) map_message.transformation = output.getTransformation() + map_message.setSequenceNum(output.getSequenceNum()) self.out.send(map_message) diff --git a/depthai_nodes/ml/parsers/mediapipe_palm_detection.py b/depthai_nodes/ml/parsers/mediapipe_palm_detection.py index deddf2bf..8b3a1432 100644 --- a/depthai_nodes/ml/parsers/mediapipe_palm_detection.py +++ b/depthai_nodes/ml/parsers/mediapipe_palm_detection.py @@ -199,5 +199,6 @@ def run(self): ) detections_msg.setTimestamp(output.getTimestamp()) detections_msg.transformation = output.getTransformation() + detections_msg.setSequenceNum(output.getSequenceNum()) self.out.send(detections_msg) diff --git a/depthai_nodes/ml/parsers/mlsd.py b/depthai_nodes/ml/parsers/mlsd.py index 696f4167..42b1c199 100644 --- a/depthai_nodes/ml/parsers/mlsd.py +++ b/depthai_nodes/ml/parsers/mlsd.py @@ -172,5 +172,6 @@ def run(self): message = create_line_detection_message(lines, np.array(scores)) message.setTimestamp(output.getTimestamp()) message.transformation = output.getTransformation() + message.setSequenceNum(output.getSequenceNum()) self.out.send(message) diff --git a/depthai_nodes/ml/parsers/ppdet.py b/depthai_nodes/ml/parsers/ppdet.py index dfe11645..a3e8ec66 100644 --- a/depthai_nodes/ml/parsers/ppdet.py +++ b/depthai_nodes/ml/parsers/ppdet.py @@ -127,5 +127,6 @@ def run(self): ) message.setTimestamp(output.getTimestamp()) message.transformation = output.getTransformation() + message.setSequenceNum(output.getSequenceNum()) self.out.send(message) diff --git a/depthai_nodes/ml/parsers/regression.py b/depthai_nodes/ml/parsers/regression.py index ed232c0b..c501fd15 100644 --- a/depthai_nodes/ml/parsers/regression.py +++ b/depthai_nodes/ml/parsers/regression.py @@ -89,5 +89,6 @@ def run(self): regression_message = create_regression_message(predictions=predictions) regression_message.setTimestamp(output.getTimestamp()) regression_message.transformation = output.getTransformation() + regression_message.setSequenceNum(output.getSequenceNum()) self.out.send(regression_message) diff --git a/depthai_nodes/ml/parsers/scrfd.py b/depthai_nodes/ml/parsers/scrfd.py index e626baa7..0585d8e2 100644 --- a/depthai_nodes/ml/parsers/scrfd.py +++ b/depthai_nodes/ml/parsers/scrfd.py @@ -218,5 +218,6 @@ def run(self): ) message.setTimestamp(output.getTimestamp()) message.transformation = output.getTransformation() + message.setSequenceNum(output.getSequenceNum()) self.out.send(message) diff --git a/depthai_nodes/ml/parsers/segmentation.py b/depthai_nodes/ml/parsers/segmentation.py index 621c2796..e4a8d91f 100644 --- a/depthai_nodes/ml/parsers/segmentation.py +++ b/depthai_nodes/ml/parsers/segmentation.py @@ -154,5 +154,6 @@ def run(self): mask_message = create_segmentation_message(class_map) mask_message.setTimestamp(output.getTimestamp()) mask_message.transformation = output.getTransformation() + mask_message.setSequenceNum(output.getSequenceNum()) self.out.send(mask_message) diff --git a/depthai_nodes/ml/parsers/superanimal_landmarker.py b/depthai_nodes/ml/parsers/superanimal_landmarker.py index 768d6a44..84e69de6 100644 --- a/depthai_nodes/ml/parsers/superanimal_landmarker.py +++ b/depthai_nodes/ml/parsers/superanimal_landmarker.py @@ -100,5 +100,6 @@ def run(self): msg = create_keypoints_message(keypoints, scores, self.score_threshold) msg.setTimestamp(output.getTimestamp()) msg.transformation = output.getTransformation() + msg.setSequenceNum(output.getSequenceNum()) self.out.send(msg) diff --git a/depthai_nodes/ml/parsers/utils/ppdet.py b/depthai_nodes/ml/parsers/utils/ppdet.py index a35d3658..ddca5679 100644 --- a/depthai_nodes/ml/parsers/utils/ppdet.py +++ b/depthai_nodes/ml/parsers/utils/ppdet.py @@ -81,7 +81,7 @@ def _box_score(predictions: np.ndarray, _corners: np.ndarray) -> float: def _unclip( box: np.ndarray, - unclip_ratio: float = 3, + unclip_ratio: float = 2, ) -> Tuple[np.ndarray, np.ndarray]: """Internal function to dilate the bounding box area by a specified ratio. @@ -94,7 +94,7 @@ def _unclip( """ box[2] = box[2] * np.sqrt(unclip_ratio) - box[3] = box[3] * unclip_ratio + box[3] = box[3] * np.sqrt(unclip_ratio) return box diff --git a/depthai_nodes/ml/parsers/xfeat.py b/depthai_nodes/ml/parsers/xfeat.py index f873f04b..0516b4dd 100644 --- a/depthai_nodes/ml/parsers/xfeat.py +++ b/depthai_nodes/ml/parsers/xfeat.py @@ -335,6 +335,7 @@ def run(self): else: matched_points = dai.TrackedFeatures() matched_points.setTimestamp(output.getTimestamp()) + matched_points.setSequenceNum(output.getSequenceNum()) self.out.send(matched_points) continue @@ -342,10 +343,14 @@ def run(self): mkpts0, mkpts1 = match(self.previous_results, result) matched_points = create_tracked_features_message(mkpts0, mkpts1) matched_points.setTimestamp(output.getTimestamp()) + matched_points.setSequenceNum(output.getSequenceNum()) + self.out.send(matched_points) else: matched_points = dai.TrackedFeatures() matched_points.setTimestamp(output.getTimestamp()) + matched_points.setSequenceNum(output.getSequenceNum()) + self.out.send(matched_points) if self.trigger: @@ -473,6 +478,8 @@ def run(self): else: matched_points = dai.TrackedFeatures() matched_points.setTimestamp(reference_output.getTimestamp()) + matched_points.setSequenceNum(reference_output.getSequenceNum()) + self.out.send(matched_points) continue @@ -481,10 +488,14 @@ def run(self): else: matched_points = dai.TrackedFeatures() matched_points.setTimestamp(target_output.getTimestamp()) + matched_points.setSequenceNum(reference_output.getSequenceNum()) + self.out.send(matched_points) continue mkpts0, mkpts1 = match(reference_result, target_result) matched_points = create_tracked_features_message(mkpts0, mkpts1) matched_points.setTimestamp(target_output.getTimestamp()) + matched_points.setSequenceNum(reference_output.getSequenceNum()) + self.out.send(matched_points) diff --git a/depthai_nodes/ml/parsers/yolo.py b/depthai_nodes/ml/parsers/yolo.py index 8dbf27c7..80fd5c3b 100644 --- a/depthai_nodes/ml/parsers/yolo.py +++ b/depthai_nodes/ml/parsers/yolo.py @@ -398,5 +398,6 @@ def run(self): detections_message.setTimestamp(output.getTimestamp()) detections_message.transformation = output.getTransformation() + detections_message.setSequenceNum(output.getSequenceNum()) self.out.send(detections_message) diff --git a/depthai_nodes/ml/parsers/yunet.py b/depthai_nodes/ml/parsers/yunet.py index 597d7d21..8130b717 100644 --- a/depthai_nodes/ml/parsers/yunet.py +++ b/depthai_nodes/ml/parsers/yunet.py @@ -297,5 +297,6 @@ def run(self): detections_message.setTimestamp(output.getTimestamp()) detections_message.transformation = output.getTransformation() + detections_message.setSequenceNum(output.getSequenceNum()) self.out.send(detections_message)