11 #include "tensorflow/core/framework/op.h"
12 #include "tensorflow/core/framework/op_kernel.h"
13 #include "tensorflow/core/lib/core/errors.h"
17 namespace voxel_pooling_opkernel {
19 template <
class TReal,
class TFeat>
20 class OutputAllocator {
24 void AllocPooledPositions(TReal** ptr,
size_t num) {
25 using namespace tensorflow;
28 TensorShape shape({int64_t(num), 3});
29 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
30 auto flat_tensor = tensor->flat<TReal>();
31 *ptr = flat_tensor.data();
34 void AllocPooledFeatures(TFeat** ptr,
size_t num,
int channels) {
35 using namespace tensorflow;
38 TensorShape shape({int64_t(num), channels});
39 OP_REQUIRES_OK(
context,
context->allocate_output(1, shape, &tensor));
40 auto flat_tensor = tensor->flat<TFeat>();
41 *ptr = flat_tensor.data();
45 tensorflow::OpKernelContext*
context;
49 class VoxelPoolingOpKernel :
public tensorflow::OpKernel {
51 explicit VoxelPoolingOpKernel(
52 tensorflow::OpKernelConstruction* construction)
53 : OpKernel(construction) {
54 using namespace tensorflow;
56 std::string pos_fn_str;
57 OP_REQUIRES_OK(construction,
58 construction->GetAttr(
"position_fn", &pos_fn_str));
60 if (pos_fn_str ==
"average")
62 else if (pos_fn_str ==
"nearest_neighbor")
67 std::string feat_fn_str;
68 OP_REQUIRES_OK(construction,
69 construction->GetAttr(
"feature_fn", &feat_fn_str));
71 if (feat_fn_str ==
"average")
73 else if (feat_fn_str ==
"nearest_neighbor")
78 OP_REQUIRES_OK(construction, construction->GetAttr(
"debug", &debug));
81 void Compute(tensorflow::OpKernelContext*
context)
override {
82 using namespace tensorflow;
84 const Tensor& positions =
context->input(0);
86 context, positions.shape().dims() == 2,
87 errors::InvalidArgument(
"positions must be a rank 2 tensor"));
89 const Tensor& features =
context->input(1);
91 context, features.shape().dims() == 2,
92 errors::InvalidArgument(
"features must be a rank 2 tensor"));
94 const Tensor& voxel_size =
context->input(2);
96 context, TensorShapeUtils::IsScalar(voxel_size.shape()),
97 errors::InvalidArgument(
"voxel_size must be a scalar, but is ",
98 voxel_size.shape().DebugString()));
100 Kernel(
context, positions, features, voxel_size);
104 virtual void Kernel(tensorflow::OpKernelContext*
context,
105 const tensorflow::Tensor& positions,
106 const tensorflow::Tensor& features,
107 const tensorflow::Tensor& voxel_size) = 0;
ImGuiContext * context
Definition: Window.cpp:76
Definition: ContinuousConv.h:16
AccumulationFn
Definition: VoxelPooling.h:21
@ CENTER
Definition: VoxelPooling.h:21
@ NEAREST_NEIGHBOR
Definition: VoxelPooling.h:21
@ MAX
Definition: VoxelPooling.h:21
@ AVERAGE
Definition: VoxelPooling.h:21