Skip to content

Commit

Permalink
fix: AgeGenderParser formatting and convert age to years
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbmrz committed Aug 16, 2024
1 parent e474346 commit 5a669b3
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions depthai_nodes/ml/parsers/age_gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,39 @@


class AgeGenderParser(dai.node.ThreadedHostNode):
def __init__(
self
):
"""Parser class for parsing the output of the Age-Gender regression model.
Attributes
----------
input : Node.Input
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.
Output Message/s
----------------
**Type**: AgeGender
**Description**: Message containing the detected person age and probabilities for each gender class.
"""

def __init__(self):
"""Initializes the AgeGenderParser node."""
dai.node.ThreadedHostNode.__init__(self)
self.input = dai.Node.Input(self)
self.out = dai.Node.Output(self)

def run(self):
"""Postprocessing logic for age_gender model.
Returns:
Detected person age and gender probability.
"""

while self.isRunning():
try:
output: dai.NNData = self.input.get()
except dai.MessageQueue.QueueException:
break # Pipeline was stopped

age = output.getTensor("age_conv3", dequantize=True)
prob = output.getTensor("prob", dequantize=True)
age = output.getTensor("age_conv3", dequantize=True).item()
age *= 100 # convert to years
prob = output.getTensor("prob", dequantize=True).flatten().tolist()

age_gender_message = create_age_gender_message(
age=age.item(),
gender_prob=prob.flatten().tolist()
)
age_gender_message = create_age_gender_message(age=age, gender_prob=prob)

self.out.send(age_gender_message)

0 comments on commit 5a669b3

Please sign in to comment.