Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NmsOpKernel.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 //#include "open3d/ml/impl/misc/VoxelPooling.h"
31 #include "tensorflow/core/framework/op.h"
32 #include "tensorflow/core/framework/op_kernel.h"
33 #include "tensorflow/core/lib/core/errors.h"
34 
36 // namespace for code that is common for all kernels
37 namespace nms_opkernel {
38 
39 class OutputAllocator {
40 public:
41  OutputAllocator(tensorflow::OpKernelContext* context) : context(context) {}
42 
43  void AllocKeepIndices(int64_t** ptr, int64_t num) {
44  using namespace tensorflow;
45  *ptr = nullptr;
46  Tensor* tensor = 0;
47  TensorShape shape({num});
48  OP_REQUIRES_OK(context, context->allocate_output(0, shape, &tensor));
49  auto flat_tensor = tensor->flat<int64>();
50  *ptr = (int64_t*)flat_tensor.data();
51  }
52 
53 private:
54  tensorflow::OpKernelContext* context;
55 };
56 
57 // Base class with common code for the OpKernel implementations
58 class NmsOpKernel : public tensorflow::OpKernel {
59 public:
60  explicit NmsOpKernel(tensorflow::OpKernelConstruction* construction)
61  : OpKernel(construction) {
62  OP_REQUIRES_OK(construction,
63  construction->GetAttr("nms_overlap_thresh",
64  &nms_overlap_thresh));
65  }
66 
67  void Compute(tensorflow::OpKernelContext* context) override {
68  using namespace tensorflow;
69  const Tensor& boxes = context->input(0);
70  const Tensor& scores = context->input(1);
71 
72  {
73  using namespace open3d::ml::op_util;
74  Dim num_points("num_points");
75  Dim five(5, "five");
76  CHECK_SHAPE(context, boxes, num_points, five);
77  CHECK_SHAPE(context, scores, num_points);
78  }
79 
80  Kernel(context, boxes, scores);
81  }
82 
83  // Function with the device specific code
84  virtual void Kernel(tensorflow::OpKernelContext* context,
85  const tensorflow::Tensor& boxes,
86  const tensorflow::Tensor& scores) = 0;
87 
88 protected:
89  float nms_overlap_thresh;
90 };
91 
92 } // namespace nms_opkernel
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:205
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:69
ImGuiContext * context
Definition: Window.cpp:95
Definition: ShapeChecking.h:35