26 #include "tensorflow/core/framework/op.h" 27 #include "tensorflow/core/framework/op_kernel.h" 28 #include "tensorflow/core/lib/core/errors.h" 30 template <
class TIndex>
34 tensorflow::OpKernelConstruction* construction)
35 : OpKernel(construction) {
38 OP_REQUIRES_OK(construction,
40 OP_REQUIRES_OK(construction,
41 construction->GetAttr(
"normalize", &
normalize));
43 std::string interpolation_str;
44 OP_REQUIRES_OK(construction, construction->GetAttr(
"interpolation",
47 if (interpolation_str ==
"linear")
49 else if (interpolation_str ==
"linear_border")
54 std::string mapping_str;
55 OP_REQUIRES_OK(construction, construction->GetAttr(
"coordinate_mapping",
58 if (mapping_str ==
"ball_to_cube_radial")
60 else if (mapping_str ==
"ball_to_cube_volume_preserving")
62 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
66 OP_REQUIRES_OK(construction, construction->GetAttr(
"max_temp_mem_MB",
70 void Compute(tensorflow::OpKernelContext* context)
override {
72 static_assert(
sizeof(int64) ==
sizeof(int64_t),
73 "int64 type is not compatible");
74 const Tensor& filter = context->input(0);
76 const Tensor& out_positions = context->input(1);
78 out_positions.shape().dim_size(0) <=
79 std::numeric_limits<TIndex>::max(),
80 errors::InvalidArgument(
"Too many output points"));
82 const Tensor& extents = context->input(2);
83 OP_REQUIRES(context, extents.shape().dims() == 2,
84 errors::InvalidArgument(
"extents must be a rank 2 tensor"));
86 extents.shape().dim_size(0) ==
87 out_positions.shape().dim_size(0) ||
88 extents.shape().dim_size(0) == 1,
89 errors::InvalidArgument(
"number of extents must match the " 90 "number of out_positions or must " 93 extents.shape().dim_size(1) == 3 ||
94 extents.shape().dim_size(1) == 1,
95 errors::InvalidArgument(
96 "number of components for extents must be 3 or 1"));
98 const Tensor&
offset = context->input(3);
99 OP_REQUIRES(context, offset.shape().dims() == 1,
100 errors::InvalidArgument(
"offset must be a rank 1 tensor"));
101 OP_REQUIRES(context, offset.shape().dim_size(0) == 3,
102 errors::InvalidArgument(
"offset length must be 3"));
104 const Tensor& inp_positions = context->input(4);
106 inp_positions.shape().dim_size(0) <=
107 std::numeric_limits<TIndex>::max(),
108 errors::InvalidArgument(
"Too many input points"));
110 const Tensor& inp_features = context->input(5);
112 const Tensor& inp_importance = context->input(6);
114 const Tensor& neighbors_index = context->input(7);
116 const Tensor& neighbors_importance = context->input(8);
118 const Tensor& neighbors_row_splits = context->input(9);
122 inp_positions.shape().dim_size(0) ==
123 inp_features.shape().dim_size(0),
124 errors::InvalidArgument(
"first dim of inp_positions does not " 125 "match the first dim of inp_features"));
128 inp_positions.shape().dim_size(0) ==
129 inp_importance.shape().dim_size(0) ||
130 inp_importance.shape().dim_size(0) == 0,
131 errors::InvalidArgument(
"first dim of inp_positions does " 132 "not match the first dim of " 136 neighbors_importance.shape().dim_size(0) ==
137 neighbors_index.shape().dim_size(0) ||
138 neighbors_importance.shape().dim_size(0) == 0,
139 errors::InvalidArgument(
"first dim of neighbors_importance " 140 "does not match the first dim of " 145 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
146 errors::InvalidArgument(
"number of input channels in filter " 147 "and inp_features does not match"));
149 TensorShape out_features_shape({out_positions.shape().dim_size(0),
150 filter.shape().dim_size(4)});
151 Tensor* out_features =
nullptr;
152 OP_REQUIRES_OK(context, context->allocate_output(0, out_features_shape,
155 std::vector<int> filter_dims({
156 int(filter.shape().dim_size(0)),
157 int(filter.shape().dim_size(1)),
158 int(filter.shape().dim_size(2)),
159 int(filter.shape().dim_size(3)),
160 int(filter.shape().dim_size(4)),
163 bool individual_extents = extents.shape().dim_size(0) ==
164 out_positions.shape().dim_size(0) &&
165 extents.shape().dim_size(0) > 1;
167 bool isotropic_extents = extents.shape().dim_size(1) == 1;
169 bool point_importances = inp_importance.shape().dim_size(0) != 0;
171 bool has_neighbors_importances =
172 neighbors_importance.shape().dim_size(0) != 0;
174 Kernel(context, filter, out_positions, extents, offset, inp_positions,
175 inp_features, inp_importance, neighbors_index,
176 neighbors_importance, neighbors_row_splits, filter_dims,
177 individual_extents, isotropic_extents, point_importances,
178 has_neighbors_importances, *out_features);
181 virtual void Kernel(tensorflow::OpKernelContext* context,
182 const tensorflow::Tensor& filter,
183 const tensorflow::Tensor& out_positions,
184 const tensorflow::Tensor& extents,
185 const tensorflow::Tensor&
offset,
186 const tensorflow::Tensor& inp_positions,
187 const tensorflow::Tensor& inp_features,
188 const tensorflow::Tensor& inp_importance,
189 const tensorflow::Tensor& neighbors_index,
190 const tensorflow::Tensor& neighbors_importance,
191 const tensorflow::Tensor& neighbors_row_splits,
192 const std::vector<int>& filter_dims,
193 const bool individual_extents,
194 const bool isotropic_extents,
195 const bool point_importances,
196 const bool has_neighbors_importances,
197 tensorflow::Tensor& out_features) = 0;
Definition: VoxelPooling.h:40
void Compute(tensorflow::OpKernelContext *context) override
Definition: ContinuousConvOpKernel.h:70
int max_temp_mem_MB
Definition: ContinuousConvOpKernel.h:204
Definition: ContinuousConvOpKernel.h:31
virtual void Kernel(tensorflow::OpKernelContext *context, const tensorflow::Tensor &filter, const tensorflow::Tensor &out_positions, const tensorflow::Tensor &extents, const tensorflow::Tensor &offset, const tensorflow::Tensor &inp_positions, const tensorflow::Tensor &inp_features, const tensorflow::Tensor &inp_importance, const tensorflow::Tensor &neighbors_index, const tensorflow::Tensor &neighbors_importance, const tensorflow::Tensor &neighbors_row_splits, const std::vector< int > &filter_dims, const bool individual_extents, const bool isotropic_extents, const bool point_importances, const bool has_neighbors_importances, tensorflow::Tensor &out_features)=0
int offset
Definition: FilePCD.cpp:64
InterpolationMode
Definition: ContinuousConvTypes.h:37
Definition: ContinuousConv.h:35
CoordinateMapping
Definition: ContinuousConvTypes.h:45
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 int
Definition: K4aPlugin.cpp:476
bool normalize
Definition: ContinuousConvOpKernel.h:201
bool align_corners
Definition: ContinuousConvOpKernel.h:200
ContinuousConvOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: ContinuousConvOpKernel.h:33
open3d::ml::impl::InterpolationMode interpolation
Definition: ContinuousConvOpKernel.h:202
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition: ContinuousConvOpKernel.h:203