30 #include "tensorflow/core/framework/op.h" 31 #include "tensorflow/core/framework/op_kernel.h" 32 #include "tensorflow/core/lib/core/errors.h" 38 template <
class TReal,
class TFeat>
39 class OutputAllocator {
41 OutputAllocator(tensorflow::OpKernelContext*
context) : context(context) {}
43 void AllocPooledPositions(TReal** ptr,
size_t num) {
47 TensorShape shape({int64_t(num), 3});
48 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
49 auto flat_tensor = tensor->flat<TReal>();
50 *ptr = flat_tensor.data();
53 void AllocPooledFeatures(TFeat** ptr,
size_t num,
int channels) {
57 TensorShape shape({int64_t(num), channels});
58 OP_REQUIRES_OK(
context,
context->allocate_output(1, shape, &tensor));
59 auto flat_tensor = tensor->flat<TFeat>();
60 *ptr = flat_tensor.data();
64 tensorflow::OpKernelContext*
context;
68 class VoxelPoolingOpKernel :
public tensorflow::OpKernel {
70 explicit VoxelPoolingOpKernel(
71 tensorflow::OpKernelConstruction* construction)
72 : OpKernel(construction) {
75 std::string pos_fn_str;
76 OP_REQUIRES_OK(construction,
77 construction->GetAttr(
"position_fn", &pos_fn_str));
79 if (pos_fn_str ==
"average")
81 else if (pos_fn_str ==
"nearest_neighbor")
86 std::string feat_fn_str;
87 OP_REQUIRES_OK(construction,
88 construction->GetAttr(
"feature_fn", &feat_fn_str));
90 if (feat_fn_str ==
"average")
92 else if (feat_fn_str ==
"nearest_neighbor")
97 OP_REQUIRES_OK(construction, construction->GetAttr(
"debug", &debug));
100 void Compute(tensorflow::OpKernelContext*
context)
override {
103 const Tensor& positions = context->input(0);
105 context, positions.shape().dims() == 2,
106 errors::InvalidArgument(
"positions must be a rank 2 tensor"));
108 const Tensor& features = context->input(1);
110 context, features.shape().dims() == 2,
111 errors::InvalidArgument(
"features must be a rank 2 tensor"));
113 const Tensor& voxel_size = context->input(2);
115 context, TensorShapeUtils::IsScalar(voxel_size.shape()),
116 errors::InvalidArgument(
"voxel_size must be a scalar, but is ",
117 voxel_size.shape().DebugString()));
119 Kernel(context, positions, features, voxel_size);
123 virtual void Kernel(tensorflow::OpKernelContext* context,
124 const tensorflow::Tensor& positions,
125 const tensorflow::Tensor& features,
126 const tensorflow::Tensor& voxel_size) = 0;
Definition: VoxelPooling.h:40
Definition: VoxelPooling.h:40
Definition: VoxelPooling.h:40
ImGuiContext * context
Definition: Window.cpp:95
Definition: ContinuousConv.h:35
AccumulationFn
Definition: VoxelPooling.h:40
Definition: VoxelPooling.h:40