12 #include "absl/status/status.h"
14 #include "tensorflow/core/framework/op.h"
15 #include "tensorflow/core/framework/op_kernel.h"
16 #include "tensorflow/core/lib/core/errors.h"
20 namespace voxel_pooling_opkernel {
22 template <
class TReal,
class TFeat>
23 class OutputAllocator {
27 void AllocPooledPositions(TReal** ptr,
size_t num) {
28 using namespace tensorflow;
31 TensorShape shape({int64_t(num), 3});
32 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
33 auto flat_tensor = tensor->flat<TReal>();
34 *ptr = flat_tensor.data();
37 void AllocPooledFeatures(TFeat** ptr,
size_t num,
int channels) {
38 using namespace tensorflow;
41 TensorShape shape({int64_t(num), channels});
42 OP_REQUIRES_OK(
context,
context->allocate_output(1, shape, &tensor));
43 auto flat_tensor = tensor->flat<TFeat>();
44 *ptr = flat_tensor.data();
48 tensorflow::OpKernelContext*
context;
52 class VoxelPoolingOpKernel :
public tensorflow::OpKernel {
54 explicit VoxelPoolingOpKernel(
55 tensorflow::OpKernelConstruction* construction)
56 : OpKernel(construction) {
57 using namespace tensorflow;
59 std::string pos_fn_str;
60 OP_REQUIRES_OK(construction,
61 construction->GetAttr(
"position_fn", &pos_fn_str));
63 if (pos_fn_str ==
"average")
65 else if (pos_fn_str ==
"nearest_neighbor")
70 std::string feat_fn_str;
71 OP_REQUIRES_OK(construction,
72 construction->GetAttr(
"feature_fn", &feat_fn_str));
74 if (feat_fn_str ==
"average")
76 else if (feat_fn_str ==
"nearest_neighbor")
81 OP_REQUIRES_OK(construction, construction->GetAttr(
"debug", &debug));
84 void Compute(tensorflow::OpKernelContext*
context)
override {
85 using namespace tensorflow;
87 const Tensor& positions =
context->input(0);
88 OP_REQUIRES(
context, positions.shape().dims() == 2,
89 absl::InvalidArgumentError(
90 "positions must be a rank 2 tensor"));
92 const Tensor& features =
context->input(1);
94 context, features.shape().dims() == 2,
95 absl::InvalidArgumentError(
"features must be a rank 2 tensor"));
97 const Tensor& voxel_size =
context->input(2);
99 context, TensorShapeUtils::IsScalar(voxel_size.shape()),
100 absl::InvalidArgumentError(
101 std::string(
"voxel_size must be a scalar, but is ") +
102 voxel_size.shape().DebugString()));
104 Kernel(
context, positions, features, voxel_size);
108 virtual void Kernel(tensorflow::OpKernelContext*
context,
109 const tensorflow::Tensor& positions,
110 const tensorflow::Tensor& features,
111 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