STM32N6 NPU Deployment — Politecnico di Milano  1.0
Documentation for Neural Network Deployment on STM32N6 NPU - Politecnico di Milano 2024-2025
metrics Namespace Reference

Functions

def _oks_matrix (tf.Tensor kpt0, tf.Tensor kpt1, tf.Tensor area, tf.Tensor stddev, Optional[float] eps=1e-7)
 
def _pose_area_calculation (tf.Tensor tensor)
 
def _matching_predictions (tf.Tensor tensor, tf.Tensor thres)
 
def single_pose_oks (tf.Tensor y_true, tf.Tensor y_pred)
 
def single_pose_heatmaps_oks (tf.Tensor y_true, tf.Tensor y_pred)
 
def multi_pose_oks_mAP (tf.Tensor y_true, tf.Tensor y_pred)
 
def _precision_recall (tf.Tensor tp, tf.Tensor conf, tf.Tensor nb_gt, tf.Tensor maskpad, Optional[float] eps=1e-7)
 
def _auc (tf.Tensor precision, tf.Tensor recall)
 
def compute_ap (tf.Tensor tp, tf.Tensor conf, tf.Tensor nb_gt, tf.Tensor maskpad, bool plot_metrics)
 

Function Documentation

◆ _auc()

def metrics._auc ( tf.Tensor  precision,
tf.Tensor  recall 
)
private
Compute the Area Under the Curve (AUC) that gives the mAP value

Args
    precision (tf.Tensor): shape (thres, ) FLOAT32 precision values for all the thresholds
    recall    (tf.Tensor): shape (thres, ) FLOAT32 recall values for all the thresholds

Returns:
    mAP (tf.Tensor): shape (1, ) FLOAT32 mean Average Precision value

Definition at line 269 of file metrics.py.

Referenced by compute_ap().

Here is the caller graph for this function:

◆ _matching_predictions()

def metrics._matching_predictions ( tf.Tensor  tensor,
tf.Tensor  thres 
)
private
Matching of the predictions with the ground truths

Args
    tensor   (tf.Tensor): shape (batch, N, M) FLOAT32 representing the object keypoint similarities.
    thres    (tf.Tensor): shape (thres, )     FLOAT32 thresholds for the OKS

Returns:
    matching (tf.Tensor): shape (batch, M, thres) FLOAT32 0 and 1's representing the matching of the preds with a gt for every thresholds.

Definition at line 77 of file metrics.py.

Referenced by multi_pose_oks_mAP().

Here is the caller graph for this function:

◆ _oks_matrix()

def metrics._oks_matrix ( tf.Tensor  kpt0,
tf.Tensor  kpt1,
tf.Tensor  area,
tf.Tensor  stddev,
Optional[float]   eps = 1e-7 
)
private
Calculate OKS (object keypoint similarities) matrix

Args
    kpt0   (tf.Tensor): shape (batch, N, nb_kpts, 3) FLOAT32 representing ground truth keypoints.
    kpt1   (tf.Tensor): shape (batch, M, nb_kpts, 3) FLOAT32 representing predicted keypoints.
    area   (tf.Tensor): shape (batch, N) FLOAT32 representing areas of the poses of the gt kpts.
    stddev (tf.Tensor): shape (nb_kpts, ) FLOAT32 representing the normalized keypoints standard deviation
    eps     Optional[float]: shape (1,)   FLOAT32 value used to avoid division by zero

Returns:
    oks    (tf.Tensor): shape (batch, N, M) representing the object keypoint similarities.

Definition at line 32 of file metrics.py.

Referenced by multi_pose_oks_mAP(), and single_pose_oks().

Here is the caller graph for this function:

◆ _pose_area_calculation()

def metrics._pose_area_calculation ( tf.Tensor  tensor)
private
Calculate the area of a pose

Args
    tensor (tf.Tensor): shape (batch, N, 2) FLOAT32 bounding box [w h] values

Returns:
    area   (tf.Tensor): shape (batch, N) FLOAT32 W*H area of the poses

Definition at line 62 of file metrics.py.

Referenced by multi_pose_oks_mAP(), and single_pose_oks().

Here is the caller graph for this function:

◆ _precision_recall()

def metrics._precision_recall ( tf.Tensor  tp,
tf.Tensor  conf,
tf.Tensor  nb_gt,
tf.Tensor  maskpad,
Optional[float]   eps = 1e-7 
)
private
Compute precision and recall for all thresholds

Args
    tp      (tf.Tensor):     shape (batch*M,thresh) FLOAT32 0's and 1's representing the true positives
    conf    (tf.Tensor):     shape (batch*M,)       FLOAT32 box confidences of the detections
    nb_gt   (tf.Tensor):     shape (1,)             FLOAT32 number ground truths
    maskpad (tf.Tensor):     shape (batch*M,)       FLOAT32 mask for the padding of predictions
    eps     Optional[float]: shape (1,)             FLOAT32 value used to avoid division by zero

Returns:
    precision (tf.Tensor): shape (thres, ) FLOAT32 precision values for all the thresholds
    recall    (tf.Tensor): shape (thres, ) FLOAT32 recall values for all the thresholds

Definition at line 239 of file metrics.py.

Referenced by compute_ap().

Here is the caller graph for this function:

◆ compute_ap()

def metrics.compute_ap ( tf.Tensor  tp,
tf.Tensor  conf,
tf.Tensor  nb_gt,
tf.Tensor  maskpad,
bool  plot_metrics 
)
Compute the AP (Average Precision) for each threshold values

Args
    tp      (tf.Tensor): shape (batch*M,thresh) FLOAT32 0's and 1's representing the true positives
    conf    (tf.Tensor): shape (batch*M,)       FLOAT32 box confidences of the detections
    nb_gt   (tf.Tensor): shape (1,)             FLOAT32 number ground truths
    maskpad (tf.Tensor): shape (batch*M,)       FLOAT32 mask for the padding of predictions
    plot_metrics (bool): shape (1,)             BOOL    if true the precision/recall curve will be drawn

Returns:
    mAPs (tf.Tensor): shape (thresh, ) FLOAT32 mean Average Precision values

Definition at line 300 of file metrics.py.

References _auc(), and _precision_recall().

Referenced by evaluate.evaluate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ multi_pose_oks_mAP()

def metrics.multi_pose_oks_mAP ( tf.Tensor  y_true,
tf.Tensor  y_pred 
)
Compute the OKS mAP (object keypoint similarities - mean Average Precision) metric for multi pose estimation

Args
    y_true  (tf.Tensor): shape (batch, N, 5+nb_kpts*3) FLOAT32 representing ground truth keypoints.
    y_pred  (tf.Tensor): shape (batch, M, 5+nb_kpts*3) FLOAT32 representing predicted keypoints.

Returns:
    tp      (tf.Tensor): shape (batch*M,thresh) FLOAT32 0's and 1's representing the true positives
    conf    (tf.Tensor): shape (batch*M,)       FLOAT32 box confidences of the detections
    nb_gt   (tf.Tensor): shape (1,)             FLOAT32 number ground truths
    maskpad (tf.Tensor): shape (batch*M,)       FLOAT32 mask for the padding of predictions

Definition at line 191 of file metrics.py.

References _matching_predictions(), _oks_matrix(), and _pose_area_calculation().

Referenced by evaluate.evaluate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ single_pose_heatmaps_oks()

def metrics.single_pose_heatmaps_oks ( tf.Tensor  y_true,
tf.Tensor  y_pred 
)
Compute the OKS (object keypoint similarities) metric for single pose estimation heatmaps

Args
    y_true  (tf.Tensor): shape (batch, 1, 5+nb_kpts*3) FLOAT32 representing ground truth keypoints.
    y_pred  (tf.Tensor): shape (batch, res, res, keypoints) FLOAT32 representing predicted heatmaps.

Returns:
    spe_oks (tf.Tensor): shape (batch,) representing the object keypoint similarities.

Definition at line 177 of file metrics.py.

References postprocess.heatmaps_spe_postprocess(), and single_pose_oks().

Here is the call graph for this function:

◆ single_pose_oks()

def metrics.single_pose_oks ( tf.Tensor  y_true,
tf.Tensor  y_pred 
)
Compute the OKS (object keypoint similarities) metric for single pose estimation

Args
    y_true  (tf.Tensor): shape (batch, 1, 5+nb_kpts*3) FLOAT32 representing ground truth keypoints.
    y_pred  (tf.Tensor): shape (batch, 1, nb_kpts*3) FLOAT32 representing predicted keypoints.

Returns:
    spe_oks (tf.Tensor): shape (batch,) representing the object keypoint similarities.

Definition at line 144 of file metrics.py.

References _oks_matrix(), and _pose_area_calculation().

Referenced by evaluate.evaluate(), and single_pose_heatmaps_oks().

Here is the call graph for this function:
Here is the caller graph for this function: