From 1a60a0e2d60434bf9411c75aa7c938cdcfea9123 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Fri, 17 Feb 2023 10:28:08 -0800 Subject: [PATCH] Use `box_output_format` to decide keypoint order PiperOrigin-RevId: 510464960 --- .../tensor/tensors_to_detections_calculator.cc | 18 +++++++++++++----- .../tensors_to_detections_calculator.proto | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc b/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc index 45393d4f1..c8dd0e2a0 100644 --- a/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc +++ b/mediapipe/calculators/tensor/tensors_to_detections_calculator.cc @@ -796,11 +796,19 @@ absl::Status TensorsToDetectionsCalculator::DecodeBoxes( const int offset = i * num_coords_ + options_.keypoint_coord_offset() + k * options_.num_values_per_keypoint(); - float keypoint_y = raw_boxes[offset]; - float keypoint_x = raw_boxes[offset + 1]; - if (options_.reverse_output_order()) { - keypoint_x = raw_boxes[offset]; - keypoint_y = raw_boxes[offset + 1]; + float keypoint_y = 0.0; + float keypoint_x = 0.0; + switch (box_output_format_) { + case mediapipe::TensorsToDetectionsCalculatorOptions::UNSPECIFIED: + case mediapipe::TensorsToDetectionsCalculatorOptions::YXHW: + keypoint_y = raw_boxes[offset]; + keypoint_x = raw_boxes[offset + 1]; + break; + case mediapipe::TensorsToDetectionsCalculatorOptions::XYWH: + case mediapipe::TensorsToDetectionsCalculatorOptions::XYXY: + keypoint_x = raw_boxes[offset]; + keypoint_y = raw_boxes[offset + 1]; + break; } (*boxes)[offset] = keypoint_x / options_.x_scale() * anchors[i].w() + diff --git a/mediapipe/calculators/tensor/tensors_to_detections_calculator.proto b/mediapipe/calculators/tensor/tensors_to_detections_calculator.proto index 1ebdcce0b..5cedff6c7 100644 --- a/mediapipe/calculators/tensor/tensors_to_detections_calculator.proto +++ b/mediapipe/calculators/tensor/tensors_to_detections_calculator.proto @@ -116,14 +116,16 @@ message TensorsToDetectionsCalculatorOptions { // Tells the calculator how to convert the detector output to bounding boxes. // Replaces `reverse_output_order` to support more bbox output formats. + // As with `reverse_output_order`, this also informs calculator the order + // of keypoint predictions. enum BoxFormat { // if UNSPECIFIED, the calculator assumes YXHW UNSPECIFIED = 0; - // [y_center, x_center, height, width] + // bbox [y_center, x_center, height, width], keypoint [y, x] YXHW = 1; - // [x_center, y_center, width, height] + // bbox [x_center, y_center, width, height], keypoint [x, y] XYWH = 2; - // [xmin, ymin, xmax, ymax] + // bbox [xmin, ymin, xmax, ymax], keypoint [x, y] XYXY = 3; } optional BoxFormat box_format = 24 [default = UNSPECIFIED];