Open3D (C++ API)  0.19.0+1a9eb99
Loading...
Searching...
No Matches
ContinuousConvOpKernel.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include <cstdint>
11
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"
17
18template <class TIndex>
19class ContinuousConvOpKernel : public tensorflow::OpKernel {
20public:
22 tensorflow::OpKernelConstruction* construction)
23 : OpKernel(construction) {
24 using namespace tensorflow;
25 using namespace open3d::ml::impl;
26 OP_REQUIRES_OK(construction,
27 construction->GetAttr("align_corners", &align_corners));
28 OP_REQUIRES_OK(construction,
29 construction->GetAttr("normalize", &normalize));
30
31 std::string interpolation_str;
32 OP_REQUIRES_OK(construction, construction->GetAttr("interpolation",
33 &interpolation_str));
34
35 if (interpolation_str == "linear")
36 interpolation = InterpolationMode::LINEAR;
37 else if (interpolation_str == "linear_border")
38 interpolation = InterpolationMode::LINEAR_BORDER;
39 else
40 interpolation = InterpolationMode::NEAREST_NEIGHBOR;
41
42 std::string mapping_str;
43 OP_REQUIRES_OK(construction, construction->GetAttr("coordinate_mapping",
44 &mapping_str));
45
46 if (mapping_str == "ball_to_cube_radial")
47 coordinate_mapping = CoordinateMapping::BALL_TO_CUBE_RADIAL;
48 else if (mapping_str == "ball_to_cube_volume_preserving")
50 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
51 else
52 coordinate_mapping = CoordinateMapping::IDENTITY;
53
54 OP_REQUIRES_OK(construction, construction->GetAttr("max_temp_mem_MB",
56 }
57
58 void Compute(tensorflow::OpKernelContext* context) override {
59 using namespace tensorflow;
60 static_assert(sizeof(int64_t) == sizeof(int64_t),
61 "int64_t type is not compatible");
62 const Tensor& filter = context->input(0);
63
64 const Tensor& out_positions = context->input(1);
65 OP_REQUIRES(context,
66 out_positions.shape().dim_size(0) <=
67 std::numeric_limits<TIndex>::max(),
68 absl::InvalidArgumentError("Too many output points"));
69
70 const Tensor& extents = context->input(2);
71 OP_REQUIRES(
72 context, extents.shape().dims() == 2,
73 absl::InvalidArgumentError("extents must be a rank 2 tensor"));
74 OP_REQUIRES(
75 context,
76 extents.shape().dim_size(0) ==
77 out_positions.shape().dim_size(0) ||
78 extents.shape().dim_size(0) == 1,
79 absl::InvalidArgumentError("number of extents must match the "
80 "number of out_positions or must "
81 "be 1"));
82 OP_REQUIRES(context,
83 extents.shape().dim_size(1) == 3 ||
84 extents.shape().dim_size(1) == 1,
85 absl::InvalidArgumentError(
86 "number of components for extents must be 3 or 1"));
87
88 const Tensor& offset = context->input(3);
89 OP_REQUIRES(
90 context, offset.shape().dims() == 1,
91 absl::InvalidArgumentError("offset must be a rank 1 tensor"));
92 OP_REQUIRES(context, offset.shape().dim_size(0) == 3,
93 absl::InvalidArgumentError("offset length must be 3"));
94
95 const Tensor& inp_positions = context->input(4);
96 OP_REQUIRES(context,
97 inp_positions.shape().dim_size(0) <=
98 std::numeric_limits<TIndex>::max(),
99 absl::InvalidArgumentError("Too many input points"));
100
101 const Tensor& inp_features = context->input(5);
102
103 const Tensor& inp_importance = context->input(6);
104
105 const Tensor& neighbors_index = context->input(7);
106
107 const Tensor& neighbors_importance = context->input(8);
108
109 const Tensor& neighbors_row_splits = context->input(9);
110
111 OP_REQUIRES(context,
112 inp_positions.shape().dim_size(0) ==
113 inp_features.shape().dim_size(0),
114 absl::InvalidArgumentError(
115 "first dim of inp_positions does not "
116 "match the first dim of inp_features"));
117
118 OP_REQUIRES(
119 context,
120 inp_positions.shape().dim_size(0) ==
121 inp_importance.shape().dim_size(0) ||
122 inp_importance.shape().dim_size(0) == 0,
123 absl::InvalidArgumentError("first dim of inp_positions does "
124 "not match the first dim of "
125 "inp_importance"));
126
127 OP_REQUIRES(
128 context,
129 neighbors_importance.shape().dim_size(0) ==
130 neighbors_index.shape().dim_size(0) ||
131 neighbors_importance.shape().dim_size(0) == 0,
132 absl::InvalidArgumentError("first dim of neighbors_importance "
133 "does not match the first dim of "
134 "neighbors_index"));
135
136 OP_REQUIRES(
137 context,
138 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
139 absl::InvalidArgumentError("number of input channels in filter "
140 "and inp_features does not match"));
141
142 TensorShape out_features_shape({out_positions.shape().dim_size(0),
143 filter.shape().dim_size(4)});
144 Tensor* out_features = nullptr;
145 OP_REQUIRES_OK(context, context->allocate_output(0, out_features_shape,
146 &out_features));
147
148 std::vector<int> filter_dims({
149 int(filter.shape().dim_size(0)),
150 int(filter.shape().dim_size(1)),
151 int(filter.shape().dim_size(2)),
152 int(filter.shape().dim_size(3)),
153 int(filter.shape().dim_size(4)),
154 });
155
156 bool individual_extents = extents.shape().dim_size(0) ==
157 out_positions.shape().dim_size(0) &&
158 extents.shape().dim_size(0) > 1;
159
160 bool isotropic_extents = extents.shape().dim_size(1) == 1;
161
162 bool point_importances = inp_importance.shape().dim_size(0) != 0;
163
164 bool has_neighbors_importances =
165 neighbors_importance.shape().dim_size(0) != 0;
166
167 Kernel(context, filter, out_positions, extents, offset, inp_positions,
168 inp_features, inp_importance, neighbors_index,
169 neighbors_importance, neighbors_row_splits, filter_dims,
170 individual_extents, isotropic_extents, point_importances,
171 has_neighbors_importances, *out_features);
172 }
173
174 virtual void Kernel(tensorflow::OpKernelContext* context,
175 const tensorflow::Tensor& filter,
176 const tensorflow::Tensor& out_positions,
177 const tensorflow::Tensor& extents,
178 const tensorflow::Tensor& offset,
179 const tensorflow::Tensor& inp_positions,
180 const tensorflow::Tensor& inp_features,
181 const tensorflow::Tensor& inp_importance,
182 const tensorflow::Tensor& neighbors_index,
183 const tensorflow::Tensor& neighbors_importance,
184 const tensorflow::Tensor& neighbors_row_splits,
185 const std::vector<int>& filter_dims,
186 const bool individual_extents,
187 const bool isotropic_extents,
188 const bool point_importances,
189 const bool has_neighbors_importances,
190 tensorflow::Tensor& out_features) = 0;
191
192public:
198};
ImGuiContext * context
Definition Window.cpp:99
Definition ContinuousConvOpKernel.h:19
bool normalize
Definition ContinuousConvOpKernel.h:194
open3d::ml::impl::InterpolationMode interpolation
Definition ContinuousConvOpKernel.h:195
void Compute(tensorflow::OpKernelContext *context) override
Definition ContinuousConvOpKernel.h:58
bool align_corners
Definition ContinuousConvOpKernel.h:193
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
ContinuousConvOpKernel(tensorflow::OpKernelConstruction *construction)
Definition ContinuousConvOpKernel.h:21
int max_temp_mem_MB
Definition ContinuousConvOpKernel.h:197
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition ContinuousConvOpKernel.h:196
int offset
Definition FilePCD.cpp:46
Definition ContinuousConv.h:16
InterpolationMode
Definition ContinuousConvTypes.h:18
CoordinateMapping
Definition ContinuousConvTypes.h:26