10 #include "../TensorFlowHelper.h"
12 #include "tensorflow/core/framework/op.h"
13 #include "tensorflow/core/framework/op_kernel.h"
14 #include "tensorflow/core/lib/core/errors.h"
19 tensorflow::OpKernelConstruction* construction)
20 : OpKernel(construction) {
21 using namespace tensorflow;
23 OP_REQUIRES_OK(construction,
24 construction->GetAttr(
"max_hash_table_size",
29 using namespace tensorflow;
33 const Tensor& radius =
context->input(1);
34 OP_REQUIRES(
context, TensorShapeUtils::IsScalar(radius.shape()),
35 errors::InvalidArgument(
"radius must be scalar, got shape ",
36 radius.shape().DebugString()));
38 const Tensor& points_row_splits =
context->input(2);
40 const Tensor& hash_table_size_factor_tensor =
context->input(3);
43 TensorShapeUtils::IsScalar(
44 hash_table_size_factor_tensor.shape()),
45 errors::InvalidArgument(
46 "hash_table_size_factor must be scalar, got shape ",
47 hash_table_size_factor_tensor.shape().DebugString()));
48 const double hash_table_size_factor =
49 hash_table_size_factor_tensor.scalar<
double>()();
51 Dim num_points(
"num_points");
52 Dim batch_size(
"batch_size");
56 std::vector<uint32_t> hash_table_splits(batch_size.
value() + 1, 0);
57 for (
int i = 0; i < batch_size.
value(); ++i) {
58 int64_t num_points_i = points_row_splits.flat<int64>()(i + 1) -
59 points_row_splits.flat<int64>()(i);
61 int64_t hash_table_size = std::min<int64_t>(
62 std::max<int64_t>(hash_table_size_factor * num_points_i, 1),
64 hash_table_splits[i + 1] = hash_table_splits[i] + hash_table_size;
67 Tensor* hash_table_index = 0;
68 TensorShape hash_table_index_shape({num_points.
value()});
70 context->allocate_output(0, hash_table_index_shape,
73 Tensor* hash_table_cell_splits = 0;
74 TensorShape hash_table_cell_splits_shape(
75 {hash_table_splits.back() + 1});
77 context->allocate_output(1, hash_table_cell_splits_shape,
78 &hash_table_cell_splits));
80 Tensor* out_hash_table_splits = 0;
81 TensorShape out_hash_table_splits_shape({batch_size.
value() + 1});
83 context->allocate_output(2, out_hash_table_splits_shape,
84 &out_hash_table_splits));
85 for (
size_t i = 0; i < hash_table_splits.size(); ++i) {
86 out_hash_table_splits->flat<
uint32_t>()(i) = hash_table_splits[i];
90 *hash_table_index, *hash_table_cell_splits);
94 const tensorflow::Tensor&
points,
95 const tensorflow::Tensor& radius,
96 const tensorflow::Tensor& points_row_splits,
97 const std::vector<uint32_t>& hash_table_splits,
98 tensorflow::Tensor& hash_table_index,
99 tensorflow::Tensor& hash_table_cell_splits) = 0;
#define CHECK_SHAPE(tensor,...)
Definition: TorchHelper.h:186
ImGuiContext * context
Definition: Window.cpp:76
Definition: BuildSpatialHashTableOpKernel.h:16
int max_hash_table_size
Definition: BuildSpatialHashTableOpKernel.h:102
virtual void Kernel(tensorflow::OpKernelContext *context, const tensorflow::Tensor &points, const tensorflow::Tensor &radius, const tensorflow::Tensor &points_row_splits, const std::vector< uint32_t > &hash_table_splits, tensorflow::Tensor &hash_table_index, tensorflow::Tensor &hash_table_cell_splits)=0
void Compute(tensorflow::OpKernelContext *context) override
Definition: BuildSpatialHashTableOpKernel.h:28
BuildSpatialHashTableOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: BuildSpatialHashTableOpKernel.h:18
Class for dimensions for which the value should be inferred.
Definition: ShapeChecking.h:50
int64_t & value()
Definition: ShapeChecking.h:70
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 timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:548
Definition: ShapeChecking.h:16