NVIDIA DeepStream SDK API Reference

9.2 Release
sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include "nvds_eval_accumulator.h"
21 
22 #include <gst/gst.h>
23 
24 #include <string>
25 #include <vector>
26 #include <set>
27 #include <cstdint>
28 
29 /* ------------------------------------------------------------------ */
30 /* ClassMetrics */
31 /* ------------------------------------------------------------------ */
32 
34 {
35  std::string class_label;
36  float ap50 = 0.0f;
37  float ap50_95 = 0.0f;
38  float precision = 0.0f;
39  float recall = 0.0f;
40  float f1 = 0.0f;
41  uint32_t tp = 0;
42  uint32_t fp = 0;
43  uint32_t total_gt = 0;
44  bool excluded = false; /* excluded from mean (manual or auto) */
45  bool auto_excluded = false; /* true when excluded because 0 TP+FP */
46 };
47 
48 /* ------------------------------------------------------------------ */
49 /* ModelMetrics */
50 /* ------------------------------------------------------------------ */
51 
53 {
54  std::string role;
55  std::string model_name;
56  std::string model_version;
57  float ap50 = 0.0f; /* mean AP@0.5 over all classes */
58  float ap50_95 = 0.0f; /* mean AP@0.5:0.95 */
59  float mean_precision = 0.0f;
60  float mean_recall = 0.0f;
61  uint32_t frame_count = 0;
62  uint32_t frames_with_gt = 0; /* 0 = GT not available */
63  bool gt_available = false;
64  std::vector<ClassMetrics> per_class;
65 };
66 
67 /* ------------------------------------------------------------------ */
68 /* compute_metrics
69  *
70  * Compute ModelMetrics for every (role, model_name) entry in @accum.
71  * @iou_thresh is used for TP/FP classification (precision/recall/F1);
72  * AP@0.5 and AP@0.5:0.95 always use their fixed standard thresholds.
73  * ------------------------------------------------------------------ */
74 std::vector<ModelMetrics> compute_metrics (EvalAccumulator &accum,
75  float iou_thresh,
76  const std::set<std::string> &exclude_classes = {},
77  bool exclude_undetected = false);
78 
79 /* ------------------------------------------------------------------ */
80 /* build_json_report
81  *
82  * Serialise one epoch's results to a JSON string.
83  *
84  * @model_pair_name logical model_name that this epoch belongs to
85  * (identifies which ModelPairContext fired)
86  * @epoch_frames Primary frame count that triggered this epoch
87  * ------------------------------------------------------------------ */
88 std::string build_json_report (const std::string &model_pair_name,
89  const std::vector<ModelMetrics> &metrics,
90  uint32_t epoch_frames,
91  bool promoted,
92  const std::string &promoted_model);
93 
94 /* ------------------------------------------------------------------ */
95 /* post_eval_result
96  *
97  * Post a GST_MESSAGE_APPLICATION("model-eval-result") on the element's
98  * bus and optionally append the JSON to @report_file.
99  *
100  * @model_pair_name forwarded to build_json_report and included in the
101  * console summary line for easy grepping
102  * ------------------------------------------------------------------ */
103 void post_eval_result (GstElement *self,
104  const std::string &model_pair_name,
105  const std::vector<ModelMetrics> &metrics,
106  uint32_t epoch_frames,
107  bool promoted,
108  const std::string &promoted_model,
109  const std::string &report_file,
110  bool cumulative = false,
111  bool show_ap_table = false);
ClassMetrics::class_label
std::string class_label
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:35
ModelMetrics::mean_precision
float mean_precision
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:59
ClassMetrics::auto_excluded
bool auto_excluded
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:45
ModelMetrics::mean_recall
float mean_recall
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:60
ClassMetrics::f1
float f1
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:40
ClassMetrics::total_gt
uint32_t total_gt
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:43
ModelMetrics::per_class
std::vector< ClassMetrics > per_class
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:64
ClassMetrics::ap50
float ap50
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:36
ModelMetrics::ap50_95
float ap50_95
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:58
ClassMetrics::ap50_95
float ap50_95
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:37
ModelMetrics
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:52
ClassMetrics
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:33
compute_metrics
std::vector< ModelMetrics > compute_metrics(EvalAccumulator &accum, float iou_thresh, const std::set< std::string > &exclude_classes={}, bool exclude_undetected=false)
ModelMetrics::model_version
std::string model_version
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:56
ModelMetrics::role
std::string role
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:54
ModelMetrics::frames_with_gt
uint32_t frames_with_gt
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:62
ClassMetrics::tp
uint32_t tp
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:41
nvds_eval_accumulator.h
ClassMetrics::precision
float precision
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:38
ClassMetrics::excluded
bool excluded
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:44
ModelMetrics::ap50
float ap50
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:57
ClassMetrics::fp
uint32_t fp
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:42
ModelMetrics::gt_available
bool gt_available
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:63
build_json_report
std::string build_json_report(const std::string &model_pair_name, const std::vector< ModelMetrics > &metrics, uint32_t epoch_frames, bool promoted, const std::string &promoted_model)
ModelMetrics::model_name
std::string model_name
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:55
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
ModelMetrics::frame_count
uint32_t frame_count
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:61
ClassMetrics::recall
float recall
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_report.h:39
EvalAccumulator
EvalAccumulator: per-epoch accumulator across all (role, model) pairs.
Definition: sources/gst-plugins/gst-nvinfereval/nvds_eval_accumulator.h:77
post_eval_result
void post_eval_result(GstElement *self, const std::string &model_pair_name, const std::vector< ModelMetrics > &metrics, uint32_t epoch_frames, bool promoted, const std::string &promoted_model, const std::string &report_file, bool cumulative=false, bool show_ap_table=false)