31 #include "tensorflow/core/framework/op.h" 32 #include "tensorflow/core/framework/op_kernel.h" 33 #include "tensorflow/core/lib/core/errors.h" 39 class OutputAllocator {
41 OutputAllocator(tensorflow::OpKernelContext*
context) : context(context) {}
43 void AllocVoxelCoords(
int32_t** ptr, int64_t rows, int64_t cols) {
47 TensorShape shape({rows, cols});
48 OP_REQUIRES_OK(
context,
context->allocate_output(0, shape, &tensor));
49 auto flat_tensor = tensor->flat<
int32_t>();
50 *ptr = flat_tensor.data();
53 void AllocVoxelPointIndices(int64_t** ptr, int64_t num) {
57 TensorShape shape({num});
58 OP_REQUIRES_OK(
context,
context->allocate_output(1, shape, &tensor));
59 auto flat_tensor = tensor->flat<int64>();
60 *ptr = (int64_t*)flat_tensor.data();
63 void AllocVoxelPointRowSplits(int64_t** ptr, int64_t num) {
67 TensorShape shape({num});
68 OP_REQUIRES_OK(
context,
context->allocate_output(2, shape, &tensor));
69 auto flat_tensor = tensor->flat<int64>();
70 *ptr = (int64_t*)flat_tensor.data();
73 void AllocVoxelBatchSplits(int64_t** ptr, int64_t num) {
77 TensorShape shape({num});
78 OP_REQUIRES_OK(
context,
context->allocate_output(3, shape, &tensor));
79 auto flat_tensor = tensor->flat<int64>();
80 *ptr = (int64_t*)flat_tensor.data();
84 tensorflow::OpKernelContext*
context;
88 class VoxelizeOpKernel :
public tensorflow::OpKernel {
90 explicit VoxelizeOpKernel(tensorflow::OpKernelConstruction* construction)
91 : OpKernel(construction) {
92 OP_REQUIRES_OK(construction,
93 construction->GetAttr(
"max_points_per_voxel",
94 &max_points_per_voxel));
95 OP_REQUIRES_OK(construction,
96 construction->GetAttr(
"max_voxels", &max_voxels));
99 void Compute(tensorflow::OpKernelContext*
context)
override {
101 const Tensor&
points = context->input(0);
102 const Tensor& row_splits = context->input(1);
103 const Tensor& voxel_size = context->input(2);
104 const Tensor& points_range_min = context->input(3);
105 const Tensor& points_range_max = context->input(4);
109 Dim num_points(
"num_points");
116 context, ndim.value() > 0 && ndim.value() < 9,
117 errors::InvalidArgument(
118 "the number of dimensions must be in [1,..,8]"));
121 Kernel(context, points, row_splits, voxel_size, points_range_min,
126 virtual void Kernel(tensorflow::OpKernelContext* context,
127 const tensorflow::Tensor& points,
128 const tensorflow::Tensor& row_splits,
129 const tensorflow::Tensor& voxel_size,
130 const tensorflow::Tensor& points_range_min,
131 const tensorflow::Tensor& points_range_max) = 0;
134 tensorflow::int64 max_points_per_voxel;
135 tensorflow::int64 max_voxels;
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:205
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:398
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:69
ImGuiContext * context
Definition: Window.cpp:95
Definition: ShapeChecking.h:35