diff --git a/depthai_nodes/ml/parsers/keypoints.py b/depthai_nodes/ml/parsers/keypoints.py index 07d93f9c..7405a447 100644 --- a/depthai_nodes/ml/parsers/keypoints.py +++ b/depthai_nodes/ml/parsers/keypoints.py @@ -17,7 +17,7 @@ class KeypointParser(dai.node.ThreadedHostNode): Parser sends the processed network results to this output in a form of DepthAI message. It is a linking point from which the processed network results are retrieved. scale_factor : float Scale factor to divide the keypoints by. - num_keypoints : int + n_keypoints : int Number of keypoints the model detects. Output Message/s @@ -38,21 +38,21 @@ class KeypointParser(dai.node.ThreadedHostNode): def __init__( self, scale_factor=1, - num_keypoints=None, + n_keypoints=None, ): """Initializes KeypointParser node. @param scale_factor: Scale factor to divide the keypoints by. @type scale_factor: float - @param num_keypoints: Number of keypoints. - @type num_keypoints: int + @param n_keypoints: Number of keypoints. + @type n_keypoints: int """ dai.node.ThreadedHostNode.__init__(self) self.input = dai.Node.Input(self) self.out = dai.Node.Output(self) self.scale_factor = scale_factor - self.num_keypoints = num_keypoints + self.n_keypoints = n_keypoints def setScaleFactor(self, scale_factor): """Sets the scale factor to divide the keypoints by. @@ -62,16 +62,16 @@ def setScaleFactor(self, scale_factor): """ self.scale_factor = scale_factor - def setNumKeypoints(self, num_keypoints): + def setNumKeypoints(self, n_keypoints): """Sets the number of keypoints. - @param num_keypoints: Number of keypoints. - @type num_keypoints: int + @param n_keypoints: Number of keypoints. + @type n_keypoints: int """ - self.num_keypoints = num_keypoints + self.n_keypoints = n_keypoints def run(self): - if self.num_keypoints is None: + if self.n_keypoints is None: raise ValueError("Number of keypoints must be specified!") while self.isRunning(): @@ -90,14 +90,14 @@ def run(self): keypoints = output.getTensor(output_layer_names[0], dequantize=True).astype( np.float32 ) - num_coords = int(np.prod(keypoints.shape) / self.num_keypoints) + num_coords = int(np.prod(keypoints.shape) / self.n_keypoints) if num_coords not in [2, 3]: raise ValueError( f"Expected 2 or 3 coordinates per keypoint, got {num_coords}." ) - keypoints = keypoints.reshape(self.num_keypoints, num_coords) + keypoints = keypoints.reshape(self.n_keypoints, num_coords) keypoints /= self.scale_factor diff --git a/depthai_nodes/ml/parsers/mediapipe_palm_detection.py b/depthai_nodes/ml/parsers/mediapipe_palm_detection.py index 2f297d79..d00e92d5 100644 --- a/depthai_nodes/ml/parsers/mediapipe_palm_detection.py +++ b/depthai_nodes/ml/parsers/mediapipe_palm_detection.py @@ -17,11 +17,11 @@ class MPPalmDetectionParser(dai.node.ThreadedHostNode): Node's input. It is a linking point to which the Neural Network's output is linked. It accepts the output of the Neural Network node. out : Node.Output Parser sends the processed network results to this output in a form of DepthAI message. It is a linking point from which the processed network results are retrieved.Parser sends the processed network results to this output in form of messages. It is a linking point from which the processed network results are retrieved. - score_threshold : float + conf_threshold : float Confidence score threshold for detected hands. - nms_threshold : float + iou_threshold : float Non-maximum suppression threshold. - top_k : int + max_det : int Maximum number of detections to keep. Output Message/s @@ -36,23 +36,23 @@ class MPPalmDetectionParser(dai.node.ThreadedHostNode): https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker """ - def __init__(self, score_threshold=0.5, nms_threshold=0.5, top_k=100): + def __init__(self, conf_threshold=0.5, iou_threshold=0.5, max_det=100): """Initializes the MPPalmDetectionParser node. - @param score_threshold: Confidence score threshold for detected hands. - @type score_threshold: float - @param nms_threshold: Non-maximum suppression threshold. - @type nms_threshold: float - @param top_k: Maximum number of detections to keep. - @type top_k: int + @param conf_threshold: Confidence score threshold for detected hands. + @type conf_threshold: float + @param iou_threshold: Non-maximum suppression threshold. + @type iou_threshold: float + @param max_det: Maximum number of detections to keep. + @type max_det: int """ dai.node.ThreadedHostNode.__init__(self) self.input = dai.Node.Input(self) self.out = dai.Node.Output(self) - self.score_threshold = score_threshold - self.nms_threshold = nms_threshold - self.top_k = top_k + self.conf_threshold = conf_threshold + self.iou_threshold = iou_threshold + self.max_det = max_det def setConfidenceThreshold(self, threshold): """Sets the confidence score threshold for detected hands. @@ -60,23 +60,23 @@ def setConfidenceThreshold(self, threshold): @param threshold: Confidence score threshold for detected hands. @type threshold: float """ - self.score_threshold = threshold + self.conf_threshold = threshold - def setNMSThreshold(self, threshold): + def setIOUThreshold(self, threshold): """Sets the non-maximum suppression threshold. @param threshold: Non-maximum suppression threshold. @type threshold: float """ - self.nms_threshold = threshold + self.iou_threshold = threshold - def setTopK(self, top_k): + def setMaxDetections(self, max_det): """Sets the maximum number of detections to keep. - @param top_k: Maximum number of detections to keep. - @type top_k: int + @param max_det: Maximum number of detections to keep. + @type max_det: int """ - self.top_k = top_k + self.max_det = max_det def run(self): while self.isRunning(): @@ -97,7 +97,7 @@ def run(self): ) decoded_bboxes = generate_anchors_and_decode( - bboxes=bboxes, scores=scores, threshold=self.score_threshold, scale=192 + bboxes=bboxes, scores=scores, threshold=self.conf_threshold, scale=192 ) bboxes = [] @@ -116,9 +116,9 @@ def run(self): indices = cv2.dnn.NMSBoxes( bboxes, scores, - self.score_threshold, - self.nms_threshold, - top_k=self.top_k, + self.conf_threshold, + self.iou_threshold, + top_k=self.max_det, ) bboxes = np.array(bboxes)[indices] scores = np.array(scores)[indices] diff --git a/depthai_nodes/ml/parsers/scrfd.py b/depthai_nodes/ml/parsers/scrfd.py index e1ce0813..deec679e 100644 --- a/depthai_nodes/ml/parsers/scrfd.py +++ b/depthai_nodes/ml/parsers/scrfd.py @@ -14,11 +14,11 @@ class SCRFDParser(dai.node.ThreadedHostNode): Node's input. It is a linking point to which the Neural Network's output is linked. It accepts the output of the Neural Network node. out : Node.Output Parser sends the processed network results to this output in a form of DepthAI message. It is a linking point from which the processed network results are retrieved. - score_threshold : float + conf_threshold : float Confidence score threshold for detected faces. - nms_threshold : float + iou_threshold : float Non-maximum suppression threshold. - top_k : int + max_det : int Maximum number of detections to keep. feat_stride_fpn : tuple Tuple of the feature strides. @@ -36,21 +36,21 @@ class SCRFDParser(dai.node.ThreadedHostNode): def __init__( self, - score_threshold=0.5, - nms_threshold=0.5, - top_k=100, + conf_threshold=0.5, + iou_threshold=0.5, + max_det=100, input_size=(640, 640), feat_stride_fpn=(8, 16, 32), num_anchors=2, ): """Initializes the SCRFDParser node. - @param score_threshold: Confidence score threshold for detected faces. - @type score_threshold: float - @param nms_threshold: Non-maximum suppression threshold. - @type nms_threshold: float - @param top_k: Maximum number of detections to keep. - @type top_k: int + @param conf_threshold: Confidence score threshold for detected faces. + @type conf_threshold: float + @param iou_threshold: Non-maximum suppression threshold. + @type iou_threshold: float + @param max_det: Maximum number of detections to keep. + @type max_det: int @param feat_stride_fpn: List of the feature strides. @type feat_stride_fpn: tuple @param num_anchors: Number of anchors. @@ -62,9 +62,9 @@ def __init__( self.input = dai.Node.Input(self) self.out = dai.Node.Output(self) - self.score_threshold = score_threshold - self.nms_threshold = nms_threshold - self.top_k = top_k + self.conf_threshold = conf_threshold + self.iou_threshold = iou_threshold + self.max_det = max_det self.feat_stride_fpn = feat_stride_fpn self.num_anchors = num_anchors @@ -76,23 +76,23 @@ def setConfidenceThreshold(self, threshold): @param threshold: Confidence score threshold for detected faces. @type threshold: float """ - self.score_threshold = threshold + self.conf_threshold = threshold - def setNMSThreshold(self, threshold): + def setIOUThreshold(self, threshold): """Sets the non-maximum suppression threshold. @param threshold: Non-maximum suppression threshold. @type threshold: float """ - self.nms_threshold = threshold + self.iou_threshold = threshold - def setTopK(self, top_k): + def setMaxDetections(self, max_det): """Sets the maximum number of detections to keep. - @param top_k: Maximum number of detections to keep. - @type top_k: int + @param max_det: Maximum number of detections to keep. + @type max_det: int """ - self.top_k = top_k + self.max_det = max_det def setFeatStrideFPN(self, feat_stride_fpn): """Sets the feature stride of the FPN. @@ -173,8 +173,8 @@ def run(self): feat_stride_fpn=self.feat_stride_fpn, input_size=self.input_size, num_anchors=self.num_anchors, - score_threshold=self.score_threshold, - nms_threshold=self.nms_threshold, + score_threshold=self.conf_threshold, + nms_threshold=self.iou_threshold, ) detection_msg = create_detection_message( bboxes, scores, None, keypoints.tolist() diff --git a/depthai_nodes/ml/parsers/yunet.py b/depthai_nodes/ml/parsers/yunet.py index c229c995..9016b9c0 100644 --- a/depthai_nodes/ml/parsers/yunet.py +++ b/depthai_nodes/ml/parsers/yunet.py @@ -17,11 +17,11 @@ class YuNetParser(dai.node.ThreadedHostNode): Node's input. It is a linking point to which the Neural Network's output is linked. It accepts the output of the Neural Network node. out : Node.Output Parser sends the processed network results to this output in a form of DepthAI message. It is a linking point from which the processed network results are retrieved. - score_threshold : float + conf_threshold : float Confidence score threshold for detected faces. - nms_threshold : float + iou_threshold : float Non-maximum suppression threshold. - top_k : int + max_det : int Maximum number of detections to keep. Output Message/s @@ -33,26 +33,26 @@ class YuNetParser(dai.node.ThreadedHostNode): def __init__( self, - score_threshold=0.6, - nms_threshold=0.3, - top_k=5000, + conf_threshold=0.6, + iou_threshold=0.3, + max_det=5000, ): """Initializes the YuNetParser node. - @param score_threshold: Confidence score threshold for detected faces. - @type score_threshold: float - @param nms_threshold: Non-maximum suppression threshold. - @type nms_threshold: float - @param top_k: Maximum number of detections to keep. - @type top_k: int + @param conf_threshold: Confidence score threshold for detected faces. + @type conf_threshold: float + @param iou_threshold: Non-maximum suppression threshold. + @type iou_threshold: float + @param max_det: Maximum number of detections to keep. + @type max_det: int """ dai.node.ThreadedHostNode.__init__(self) self.input = dai.Node.Input(self) self.out = dai.Node.Output(self) - self.score_threshold = score_threshold - self.nms_threshold = nms_threshold - self.top_k = top_k + self.conf_threshold = conf_threshold + self.iou_threshold = iou_threshold + self.max_det = max_det def setConfidenceThreshold(self, threshold): """Sets the confidence score threshold for detected faces. @@ -60,23 +60,23 @@ def setConfidenceThreshold(self, threshold): @param threshold: Confidence score threshold for detected faces. @type threshold: float """ - self.score_threshold = threshold + self.conf_threshold = threshold - def setNMSThreshold(self, threshold): + def setIOUThreshold(self, threshold): """Sets the non-maximum suppression threshold. @param threshold: Non-maximum suppression threshold. @type threshold: float """ - self.nms_threshold = threshold + self.iou_threshold = threshold - def setTopK(self, top_k): + def setMaxDetections(self, max_det): """Sets the maximum number of detections to keep. - @param top_k: Maximum number of detections to keep. - @type top_k: int + @param max_det: Maximum number of detections to keep. + @type max_det: int """ - self.top_k = top_k + self.max_det = max_det def run(self): while self.isRunning(): @@ -113,7 +113,7 @@ def run(self): detections += decode_detections( input_size, stride, - self.score_threshold, + self.conf_threshold, cls, obj, bbox, @@ -126,9 +126,9 @@ def run(self): indices = cv2.dnn.NMSBoxes( detection_boxes, detection_scores, - self.score_threshold, - self.nms_threshold, - top_k=self.top_k, + self.conf_threshold, + self.iou_threshold, + top_k=self.max_det, ) detections = np.array(detections)[indices]