• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace functor {
26 
27 template <typename Device, typename T>
28 struct NonMaxSuppression {
29   void operator()(const Device& d, typename TTypes<float, 2>::ConstTensor boxes,
30                   typename TTypes<float, 1>::ConstTensor scores,
31                   float iou_threshold, float score_threshold,
32                   int max_output_size,
33                   typename TTypes<int, 1>::Tensor selected_indices);
34 };
35 
36 }  // namespace functor
37 
38 #if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
39 extern const int kNmsBoxesPerTread;
40 
41 // Given descending sorted box list, apply non-maximal-suppression with given
42 // threshold and select boxes to keep.
43 // - d_sorted_boxes_float_ptr: a pointer to device memory float array
44 //   containing the box corners for N boxes sorted in descending order of
45 //   scores.
46 // - num_boxes: number of boxes.
47 // - iou_threshold: the intersection-over-union (iou) threshold for elimination.
48 // - d_selected_indices: is a device pointer to int array containing sorted
49 //   indices of the boxes to keep.
50 // - h_num_boxes_to_keep: is a host pointer for returning number of items
51 //   to keep.
52 // - flip_boxes: flag reorders the boxes use lower left and upper right
53 //   corners if they are given in mixed format.
54 Status NmsGpu(const float* d_sorted_boxes_float_ptr, const int num_boxes,
55               const float iou_threshold, int* d_selected_indices,
56               int* h_num_boxes_to_keep, OpKernelContext* context,
57               const int max_boxes, bool flip_boxes = false);
58 #endif
59 
60 }  // namespace tensorflow
61 
62 #endif  // TENSORFLOW_CORE_KERNELS_IMAGENON_MAX_SUPPRESSION_OP_H_
63