Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RoiPoolOpKernel.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 "../TensorFlowHelper.h"
30 #include "tensorflow/core/framework/op.h"
31 #include "tensorflow/core/framework/op_kernel.h"
32 #include "tensorflow/core/lib/core/errors.h"
33 
34 class RoiPoolOpKernel : public tensorflow::OpKernel {
35 public:
36  explicit RoiPoolOpKernel(tensorflow::OpKernelConstruction* construction)
37  : OpKernel(construction) {
38  using namespace tensorflow;
39  OP_REQUIRES_OK(construction, construction->GetAttr("sampled_pts_num",
40  &sampled_pts_num));
41  }
42 
43  void Compute(tensorflow::OpKernelContext* context) override {
44  using namespace tensorflow;
45 
46  const Tensor& inp_tensor = context->input(0);
47  OP_REQUIRES(
48  context,
49  inp_tensor.dims() == 3 && inp_tensor.shape().dim_size(2) == 3,
50  errors::InvalidArgument("RoiPool expects "
51  "(batch_size,num_points,3) inp shape"));
52  int batch_size = inp_tensor.shape().dim_size(0);
53  int pts_num = inp_tensor.shape().dim_size(1);
54  auto inp_flat = inp_tensor.flat<float>();
55  const float* inp = &(inp_flat(0));
56 
57  const Tensor& boxes3d_tensor = context->input(1);
58  OP_REQUIRES(context,
59  boxes3d_tensor.dims() == 3 &&
60  boxes3d_tensor.shape().dim_size(2) == 7,
61  errors::InvalidArgument(
62  "RoiPool expects "
63  "(batch_size,num_boxes,7) boxes3d shape"));
64  int boxes_num = boxes3d_tensor.shape().dim_size(1);
65  auto boxes3d_flat = boxes3d_tensor.flat<float>();
66  const float* boxes3d = &(boxes3d_flat(0));
67 
68  const Tensor& feats_tensor = context->input(2);
69  OP_REQUIRES(context,
70  feats_tensor.dims() == 3 &&
71  feats_tensor.shape().dim_size(1) == pts_num,
72  errors::InvalidArgument(
73  "RoiPool expects "
74  "(batch_size,num_points,feats) feats shape"));
75  int feature_in_len = feats_tensor.shape().dim_size(2);
76  auto feats_flat = feats_tensor.flat<float>();
77  const float* feats = &(feats_flat(0));
78 
79  Tensor* out_feats;
80  OP_REQUIRES_OK(context,
81  context->allocate_output(
82  0,
83  TensorShape{batch_size, boxes_num,
84  sampled_pts_num, 3 + feature_in_len},
85  &out_feats));
86  auto out_flat0 = out_feats->flat<float>();
87  float* out0 = &(out_flat0(0));
88 
89  Tensor* out_flags;
90  OP_REQUIRES_OK(context, context->allocate_output(
91  1, TensorShape{batch_size, boxes_num},
92  &out_flags));
93  auto out_flat1 = out_flags->flat<int>();
94  int* out1 = &(out_flat1(0));
95 
96  Kernel(context, batch_size, pts_num, boxes_num, feature_in_len,
97  sampled_pts_num, inp, boxes3d, feats, out0, out1);
98  }
99 
100  virtual void Kernel(tensorflow::OpKernelContext* context,
101  int batch_size,
102  int pts_num,
103  int boxes_num,
104  int feature_in_len,
105  int sampled_pts_num,
106  const float* xyz,
107  const float* boxes3d,
108  const float* pts_feature,
109  float* pooled_features,
110  int* pooled_empty_flag) = 0;
111 
112 protected:
114 };
virtual void Kernel(tensorflow::OpKernelContext *context, int batch_size, int pts_num, int boxes_num, int feature_in_len, int sampled_pts_num, const float *xyz, const float *boxes3d, const float *pts_feature, float *pooled_features, int *pooled_empty_flag)=0
ImGuiContext * context
Definition: Window.cpp:95
void Compute(tensorflow::OpKernelContext *context) override
Definition: RoiPoolOpKernel.h:43
int sampled_pts_num
Definition: RoiPoolOpKernel.h:113
RoiPoolOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: RoiPoolOpKernel.h:36
Definition: RoiPoolOpKernel.h:34