Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RoiPoolOpKernel.h
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2020 www.open3d.org
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 // IN THE SOFTWARE.
22 // ----------------------------------------------------------------------------
23 #pragma once
24 
25 #include "../TensorFlowHelper.h"
26 #include "tensorflow/core/framework/op.h"
27 #include "tensorflow/core/framework/op_kernel.h"
28 #include "tensorflow/core/lib/core/errors.h"
29 
30 class RoiPoolOpKernel : public tensorflow::OpKernel {
31 public:
32  explicit RoiPoolOpKernel(tensorflow::OpKernelConstruction* construction)
33  : OpKernel(construction) {
34  using namespace tensorflow;
35  OP_REQUIRES_OK(construction, construction->GetAttr("sampled_pts_num",
36  &sampled_pts_num));
37  }
38 
39  void Compute(tensorflow::OpKernelContext* context) override {
40  using namespace tensorflow;
41 
42  const Tensor& inp_tensor = context->input(0);
43  OP_REQUIRES(
44  context,
45  inp_tensor.dims() == 3 && inp_tensor.shape().dim_size(2) == 3,
46  errors::InvalidArgument("RoiPool expects "
47  "(batch_size,num_points,3) inp shape"));
48  int batch_size = inp_tensor.shape().dim_size(0);
49  int pts_num = inp_tensor.shape().dim_size(1);
50  auto inp_flat = inp_tensor.flat<float>();
51  const float* inp = &(inp_flat(0));
52 
53  const Tensor& boxes3d_tensor = context->input(1);
54  OP_REQUIRES(context,
55  boxes3d_tensor.dims() == 3 &&
56  boxes3d_tensor.shape().dim_size(2) == 7,
57  errors::InvalidArgument(
58  "RoiPool expects "
59  "(batch_size,num_boxes,7) boxes3d shape"));
60  int boxes_num = boxes3d_tensor.shape().dim_size(1);
61  auto boxes3d_flat = boxes3d_tensor.flat<float>();
62  const float* boxes3d = &(boxes3d_flat(0));
63 
64  const Tensor& feats_tensor = context->input(2);
65  OP_REQUIRES(context,
66  feats_tensor.dims() == 3 &&
67  feats_tensor.shape().dim_size(1) == pts_num,
68  errors::InvalidArgument(
69  "RoiPool expects "
70  "(batch_size,num_points,feats) feats shape"));
71  int feature_in_len = feats_tensor.shape().dim_size(2);
72  auto feats_flat = feats_tensor.flat<float>();
73  const float* feats = &(feats_flat(0));
74 
75  Tensor* out_feats;
76  OP_REQUIRES_OK(context,
77  context->allocate_output(
78  0,
79  TensorShape{batch_size, boxes_num,
80  sampled_pts_num, 3 + feature_in_len},
81  &out_feats));
82  auto out_flat0 = out_feats->flat<float>();
83  float* out0 = &(out_flat0(0));
84 
85  Tensor* out_flags;
86  OP_REQUIRES_OK(context, context->allocate_output(
87  1, TensorShape{batch_size, boxes_num},
88  &out_flags));
89  auto out_flat1 = out_flags->flat<int>();
90  int* out1 = &(out_flat1(0));
91 
92  Kernel(context, batch_size, pts_num, boxes_num, feature_in_len,
93  sampled_pts_num, inp, boxes3d, feats, out0, out1);
94  }
95 
96  virtual void Kernel(tensorflow::OpKernelContext* context,
97  int batch_size,
98  int pts_num,
99  int boxes_num,
100  int feature_in_len,
101  int sampled_pts_num,
102  const float* xyz,
103  const float* boxes3d,
104  const float* pts_feature,
105  float* pooled_features,
106  int* pooled_empty_flag) = 0;
107 
108 protected:
110 };
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:39
int sampled_pts_num
Definition: RoiPoolOpKernel.h:109
RoiPoolOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: RoiPoolOpKernel.h:32
Definition: RoiPoolOpKernel.h:30