Skip to content

Commit

Permalink
Parser's parameters renaming. (#26)
Browse files Browse the repository at this point in the history
* Rename params in Keypoints parser.

* Rename params in Palm Detection parser.

* Rename params in SCRFD parser.

* Rename params in YuNet parser.
  • Loading branch information
kkeroo authored Aug 22, 2024
1 parent 101be07 commit 9a49670
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 86 deletions.
24 changes: 12 additions & 12 deletions depthai_nodes/ml/parsers/keypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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():
Expand All @@ -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

Expand Down
48 changes: 24 additions & 24 deletions depthai_nodes/ml/parsers/mediapipe_palm_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,47 +36,47 @@ 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.
@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():
Expand All @@ -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 = []
Expand All @@ -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]
Expand Down
48 changes: 24 additions & 24 deletions depthai_nodes/ml/parsers/scrfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
52 changes: 26 additions & 26 deletions depthai_nodes/ml/parsers/yunet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,50 +33,50 @@ 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.
@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():
Expand Down Expand Up @@ -113,7 +113,7 @@ def run(self):
detections += decode_detections(
input_size,
stride,
self.score_threshold,
self.conf_threshold,
cls,
obj,
bbox,
Expand All @@ -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]

Expand Down

0 comments on commit 9a49670

Please sign in to comment.