xref: /aosp_15_r20/external/tensorflow/tensorflow/core/kernels/image/non_max_suppression_op.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_KERNELS_IMAGENON_MAX_SUPPRESSION_OP_H_
17 #define TENSORFLOW_CORE_KERNELS_IMAGENON_MAX_SUPPRESSION_OP_H_
18 
19 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
20 #include "tensorflow/core/framework/numeric_types.h"
21 #include "tensorflow/core/framework/op_kernel.h"
22 #include "tensorflow/core/framework/tensor_types.h"
23 
24 namespace tensorflow {
25 
26 #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
27 extern const int kNmsBoxesPerTread;
28 
29 // Given descending sorted box list, apply non-maximal-suppression with given
30 // threshold and select boxes to keep.
31 // - d_sorted_boxes_float_ptr: a pointer to device memory float array
32 //   containing the box corners for N boxes sorted in descending order of
33 //   scores.
34 // - num_boxes: number of boxes.
35 // - iou_threshold: the intersection-over-union (iou) threshold for elimination.
36 // - d_selected_indices: is a device pointer to int array containing sorted
37 //   indices of the boxes to keep.
38 // - h_num_boxes_to_keep: is a host pointer for returning number of items
39 //   to keep.
40 // - flip_boxes: flag reorders the boxes use lower left and upper right
41 //   corners if they are given in mixed format.
42 Status NmsGpu(const float* d_sorted_boxes_float_ptr, const int num_boxes,
43               const float iou_threshold, int* d_selected_indices,
44               int* h_num_boxes_to_keep, OpKernelContext* context,
45               const int max_boxes, bool flip_boxes = false);
46 #endif
47 
48 }  // namespace tensorflow
49 
50 #endif  // TENSORFLOW_CORE_KERNELS_IMAGENON_MAX_SUPPRESSION_OP_H_
51