xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/tools/evaluation/proto/evaluation_stages.proto (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16syntax = "proto2";
17
18package tflite.evaluation;
19
20import "tensorflow/lite/tools/evaluation/proto/preprocessing_steps.proto";
21
22option cc_enable_arenas = true;
23option java_multiple_files = true;
24option java_package = "tflite.evaluation";
25
26// Defines the functionality executed by an EvaluationStage.
27//
28// Next ID: 7
29message ProcessSpecification {
30  oneof params {
31    ImagePreprocessingParams image_preprocessing_params = 1;
32    TopkAccuracyEvalParams topk_accuracy_eval_params = 2;
33    TfliteInferenceParams tflite_inference_params = 3;
34    ImageClassificationParams image_classification_params = 4;
35    ObjectDetectionAveragePrecisionParams
36        object_detection_average_precision_params = 5;
37    ObjectDetectionParams object_detection_params = 6;
38  }
39}
40
41// Latency numbers in microseconds, based on all EvaluationStage::Run() calls so
42// far.
43//
44// Next ID: 7
45message LatencyMetrics {
46  // Latency for the last Run.
47  optional int64 last_us = 1;
48  // Maximum latency observed for any Run.
49  optional int64 max_us = 2;
50  // Minimum latency observed for any Run.
51  optional int64 min_us = 3;
52  // Sum of all Run latencies.
53  optional int64 sum_us = 4;
54  // Average latency across all Runs.
55  optional double avg_us = 5;
56  // Standard deviation for latency across all Runs.
57  optional int64 std_deviation_us = 6;
58}
59
60// Statistics for an accuracy value over multiple runs of evaluation.
61//
62// Next ID: 5
63message AccuracyMetrics {
64  // Maximum value observed for any Run.
65  optional float max_value = 1;
66  // Minimum value observed for any Run.
67  optional float min_value = 2;
68  // Average value across all Runs.
69  optional double avg_value = 3;
70  // Standard deviation across all Runs.
71  optional float std_deviation = 4;
72}
73
74// Contains process-specific metrics, which may differ based on what an
75// EvaluationStage does.
76//
77// Next ID: 8
78message ProcessMetrics {
79  optional LatencyMetrics total_latency = 1;
80
81  oneof stage_metrics {
82    TopkAccuracyEvalMetrics topk_accuracy_metrics = 2;
83    TfliteInferenceMetrics tflite_inference_metrics = 3;
84    ImageClassificationMetrics image_classification_metrics = 4;
85    InferenceProfilerMetrics inference_profiler_metrics = 5;
86    ObjectDetectionAveragePrecisionMetrics
87        object_detection_average_precision_metrics = 6;
88    ObjectDetectionMetrics object_detection_metrics = 7;
89  }
90}
91
92// Parameters that define how images are preprocessed.
93//
94// Next ID: 3
95message ImagePreprocessingParams {
96  // Required.
97  repeated ImagePreprocessingStepParams steps = 1;
98  // Same as tflite::TfLiteType.
99  required int32 output_type = 2;
100}
101
102// Parameters that control TFLite inference.
103//
104// Next ID: 5
105message TfliteInferenceParams {
106  // Required
107  optional string model_file_path = 1;
108
109  enum Delegate {
110    NONE = 0;
111    NNAPI = 1;
112    GPU = 2;
113    HEXAGON = 3;
114    XNNPACK = 4;
115    COREML = 5;
116  }
117  optional Delegate delegate = 2;
118  // Number of threads available to the TFLite Interpreter.
119  optional int32 num_threads = 3 [default = 1];
120
121  // Defines how many times the TFLite Interpreter is invoked for every input.
122  // This helps benchmark cases where extensive pre-processing might not be
123  // required for every input.
124  optional int32 invocations_per_run = 4 [default = 1];
125}
126
127// Metrics specific to TFLite inference.
128//
129// Next ID: 2
130message TfliteInferenceMetrics {
131  // Number of times the interpreter is invoked.
132  optional int32 num_inferences = 1;
133}
134
135// Parameters that define how top-K accuracy is evaluated.
136//
137// Next ID: 2
138message TopkAccuracyEvalParams {
139  // Required.
140  optional int32 k = 1;
141}
142
143// Metrics from top-K accuracy evaluation.
144//
145// Next ID: 2
146message TopkAccuracyEvalMetrics {
147  // A repeated field of size |k| where the ith element denotes the fraction of
148  // samples for which the correct label was present in the top (i + 1) model
149  // outputs.
150  // For example, topk_accuracies(1) will contain the fraction of
151  // samples for which the model returned the correct label as the top first or
152  // second output.
153  repeated float topk_accuracies = 1;
154}
155
156// Parameters that define how the Image Classification task is evaluated
157// end-to-end.
158//
159// Next ID: 3
160message ImageClassificationParams {
161  // Required.
162  // TfLite model should have 1 input & 1 output tensor.
163  // Input shape: {1, image_height, image_width, 3}
164  // Output shape: {1, num_total_labels}
165  optional TfliteInferenceParams inference_params = 1;
166
167  // Optional.
168  // If not set, accuracy evaluation is not performed.
169  optional TopkAccuracyEvalParams topk_accuracy_eval_params = 2;
170}
171
172// Metrics from evaluation of the image classification task.
173//
174// Next ID: 5
175message ImageClassificationMetrics {
176  optional LatencyMetrics pre_processing_latency = 1;
177  optional LatencyMetrics inference_latency = 2;
178  optional TfliteInferenceMetrics inference_metrics = 3;
179  // Not set if topk_accuracy_eval_params was not populated in
180  // ImageClassificationParams.
181  optional TopkAccuracyEvalMetrics topk_accuracy_metrics = 4;
182}
183
184// Metrics computed from comparing TFLite execution in two settings:
185// 1. User-defined TfliteInferenceParams (The 'test' setting)
186// 2. Default TfliteInferenceParams (The 'reference' setting)
187//
188// Next ID: 4
189message InferenceProfilerMetrics {
190  // Latency metrics from Single-thread CPU inference.
191  optional LatencyMetrics reference_latency = 1;
192  // Latency from TfliteInferenceParams under test.
193  optional LatencyMetrics test_latency = 2;
194  // For reference & test output vectors {R, T}, the error is computed as:
195  // Mean([Abs(R[i] - T[i]) for i in num_elements])
196  // output_errors[v] : statistics for the error value of the vth output vector
197  //   across all Runs.
198  repeated AccuracyMetrics output_errors = 3;
199}
200
201// Proto containing information about all the objects (predicted or
202// ground-truth) contained in an image.
203//
204// Next ID: 4
205message ObjectDetectionResult {
206  // One instance of an object detected in an image.
207  // Next ID: 4
208  message ObjectInstance {
209    // Defines the bounding box for a detected object.
210    // Next ID: 5
211    message NormalizedBoundingBox {
212      // All boundaries defined below are required.
213      // Each boundary value should be normalized with respect to the image
214      // dimensions. This helps evaluate detections independent of image size.
215      // For example, normalized_top = top_boundary / image_height.
216      optional float normalized_top = 1;
217      optional float normalized_bottom = 2;
218      optional float normalized_left = 3;
219      optional float normalized_right = 4;
220    }
221
222    // Required.
223    optional int32 class_id = 1;
224    // Required
225    optional NormalizedBoundingBox bounding_box = 2;
226    // Value in (0, 1.0] denoting confidence in this prediction.
227    // Default value of 1.0 for ground-truth data.
228    optional float score = 3 [default = 1.0];
229  }
230
231  repeated ObjectInstance objects = 1;
232  // Filename of the image.
233  optional string image_name = 2;
234  // Unique id for the image.
235  optional int64 image_id = 3;
236}
237
238// Proto containing ground-truth ObjectsSets for all images in a COCO validation
239// set.
240//
241// Next ID: 2
242message ObjectDetectionGroundTruth {
243  repeated ObjectDetectionResult detection_results = 1;
244}
245
246// Parameters that define how Average Precision is computed for Object Detection
247// task.
248// Refer for details: http://cocodataset.org/#detection-eval
249//
250// Next ID: 4
251message ObjectDetectionAveragePrecisionParams {
252  // Total object classes. The AP value returned for each IoU threshold is an
253  // average over all classes encountered in predicted/ground truth sets.
254  optional int32 num_classes = 1;
255  // A predicted box matches a ground truth box if and only if
256  // IoU between these two are larger than an IoU threshold.
257  // AP is computed for all relevant {IoU threshold, class} combinations and
258  // averaged to get mAP.
259  // If left empty, evaluation is done for all IoU threshods in the range
260  // 0.5:0.05:0.95 (min:increment:max).
261  repeated float iou_thresholds = 2;
262  // AP is computed as the average of maximum precision at (1
263  // + num_recall_points) recall levels. E.g., if num_recall_points is 10,
264  // recall levels are 0., 0.1, 0.2, ..., 0.9, 1.0.
265  // Default: 100
266  optional int32 num_recall_points = 3 [default = 100];
267}
268
269// Average Precision metrics from Object Detection task.
270//
271// Next ID: 3
272message ObjectDetectionAveragePrecisionMetrics {
273  // Average Precision value for a particular IoU threshold.
274  // Next ID: 3
275  message AveragePrecision {
276    optional float iou_threshold = 1;
277    optional float average_precision = 2;
278  }
279
280  // One entry for each in
281  // ObjectDetectionAveragePrecisionParams::iou_thresholds, averaged over all
282  // classes.
283  repeated AveragePrecision individual_average_precisions = 1;
284  // Average of Average Precision across all IoU thresholds.
285  optional float overall_mean_average_precision = 2;
286}
287
288// Parameters that define how the Object Detection task is evaluated
289// end-to-end.
290//
291// Next ID: 4
292message ObjectDetectionParams {
293  // Required.
294  // Model's outputs should be same as a TFLite-compatible SSD model.
295  // Refer:
296  // https://www.tensorflow.org/lite/examples/object_detection/overview#output_signature
297  optional TfliteInferenceParams inference_params = 1;
298  // Optional. Used to match ground-truth categories with model output.
299  // SSD Mobilenet V1 Model trained on COCO assumes class 0 is background class
300  // in the label file and class labels start from 1 to number_of_classes+1.
301  // Therefore, default value is set as 1.
302  optional int32 class_offset = 2 [default = 1];
303  optional ObjectDetectionAveragePrecisionParams ap_params = 3;
304}
305
306// Metrics from evaluation of the object detection task.
307//
308// Next ID: 5
309message ObjectDetectionMetrics {
310  optional LatencyMetrics pre_processing_latency = 1;
311  optional LatencyMetrics inference_latency = 2;
312  optional TfliteInferenceMetrics inference_metrics = 3;
313  optional ObjectDetectionAveragePrecisionMetrics average_precision_metrics = 4;
314}
315