Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
RoiPoolOpKernel.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2024 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include "../TensorFlowHelper.h"
11#include "tensorflow/core/framework/op.h"
12#include "tensorflow/core/framework/op_kernel.h"
13#include "tensorflow/core/lib/core/errors.h"
14
15class RoiPoolOpKernel : public tensorflow::OpKernel {
16public:
17 explicit RoiPoolOpKernel(tensorflow::OpKernelConstruction* construction)
18 : OpKernel(construction) {
19 using namespace tensorflow;
20 OP_REQUIRES_OK(construction, construction->GetAttr("sampled_pts_num",
22 }
23
24 void Compute(tensorflow::OpKernelContext* context) override {
25 using namespace tensorflow;
26
27 const Tensor& inp_tensor = context->input(0);
28 OP_REQUIRES(
29 context,
30 inp_tensor.dims() == 3 && inp_tensor.shape().dim_size(2) == 3,
31 absl::InvalidArgumentError(
32 "RoiPool expects "
33 "(batch_size,num_points,3) inp shape"));
34 int batch_size = inp_tensor.shape().dim_size(0);
35 int pts_num = inp_tensor.shape().dim_size(1);
36 auto inp_flat = inp_tensor.flat<float>();
37 const float* inp = &(inp_flat(0));
38
39 const Tensor& boxes3d_tensor = context->input(1);
40 OP_REQUIRES(context,
41 boxes3d_tensor.dims() == 3 &&
42 boxes3d_tensor.shape().dim_size(2) == 7,
43 absl::InvalidArgumentError(
44 "RoiPool expects "
45 "(batch_size,num_boxes,7) boxes3d shape"));
46 int boxes_num = boxes3d_tensor.shape().dim_size(1);
47 auto boxes3d_flat = boxes3d_tensor.flat<float>();
48 const float* boxes3d = &(boxes3d_flat(0));
49
50 const Tensor& feats_tensor = context->input(2);
51 OP_REQUIRES(context,
52 feats_tensor.dims() == 3 &&
53 feats_tensor.shape().dim_size(1) == pts_num,
54 absl::InvalidArgumentError(
55 "RoiPool expects "
56 "(batch_size,num_points,feats) feats shape"));
57 int feature_in_len = feats_tensor.shape().dim_size(2);
58 auto feats_flat = feats_tensor.flat<float>();
59 const float* feats = &(feats_flat(0));
60
61 Tensor* out_feats;
62 OP_REQUIRES_OK(context,
63 context->allocate_output(
64 0,
65 TensorShape{batch_size, boxes_num,
66 sampled_pts_num, 3 + feature_in_len},
67 &out_feats));
68 auto out_flat0 = out_feats->flat<float>();
69 float* out0 = &(out_flat0(0));
70
71 Tensor* out_flags;
72 OP_REQUIRES_OK(context, context->allocate_output(
73 1, TensorShape{batch_size, boxes_num},
74 &out_flags));
75 auto out_flat1 = out_flags->flat<int>();
76 int* out1 = &(out_flat1(0));
77
78 Kernel(context, batch_size, pts_num, boxes_num, feature_in_len,
79 sampled_pts_num, inp, boxes3d, feats, out0, out1);
80 }
81
82 virtual void Kernel(tensorflow::OpKernelContext* context,
83 int batch_size,
84 int pts_num,
85 int boxes_num,
86 int feature_in_len,
88 const float* xyz,
89 const float* boxes3d,
90 const float* pts_feature,
91 float* pooled_features,
92 int* pooled_empty_flag) = 0;
93
94protected:
96};
ImGuiContext * context
Definition Window.cpp:99
Definition RoiPoolOpKernel.h:15
RoiPoolOpKernel(tensorflow::OpKernelConstruction *construction)
Definition RoiPoolOpKernel.h:17
int sampled_pts_num
Definition RoiPoolOpKernel.h:95
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
void Compute(tensorflow::OpKernelContext *context) override
Definition RoiPoolOpKernel.h:24