Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
ContinuousConvTransposeOpKernel.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 ContinuousConvTransposeOpKernel : 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& out_importance = context->input(2);
71 OP_REQUIRES(
72 context,
73 out_importance.shape().dim_size(0) == 0 ||
74 out_importance.shape().dim_size(0) ==
75 out_positions.shape().dim_size(0),
76 absl::InvalidArgumentError("length of out_importance must "
77 "match the number of output points "
78 "or must be 0"));
79
80 const Tensor& extents = context->input(3);
81
82 const Tensor& offset = context->input(4);
83 OP_REQUIRES(
84 context, offset.shape().dims() == 1,
85 absl::InvalidArgumentError("offset must be a rank 1 tensor"));
86 OP_REQUIRES(context, offset.shape().dim_size(0) == 3,
87 absl::InvalidArgumentError("offset length must be 3"));
88
89 const Tensor& inp_positions = context->input(5);
90 OP_REQUIRES(context,
91 inp_positions.shape().dim_size(0) <=
92 std::numeric_limits<TIndex>::max(),
93 absl::InvalidArgumentError("Too many input points"));
94
95 const Tensor& inp_features = context->input(6);
96
97 // not used in forward pass
98 // const Tensor& inp_neighbors_index = context->input(7);
99
100 const Tensor& inp_neighbors_importance_sum = context->input(8);
101
102 const Tensor& inp_neighbors_row_splits = context->input(9);
103
104 const Tensor& neighbors_index = context->input(10);
105
106 const Tensor& neighbors_importance = context->input(11);
107
108 const Tensor& neighbors_row_splits = context->input(12);
109
110 OP_REQUIRES(
111 context, extents.shape().dims() == 2,
112 absl::InvalidArgumentError("extents must be a rank 2 tensor"));
113 OP_REQUIRES(
114 context,
115 extents.shape().dim_size(0) ==
116 inp_positions.shape().dim_size(0) ||
117 extents.shape().dim_size(0) == 1,
118 absl::InvalidArgumentError("number of extents must match the "
119 "number of inp_positions or must "
120 "be 1"));
121 OP_REQUIRES(context,
122 extents.shape().dim_size(1) == 3 ||
123 extents.shape().dim_size(1) == 1,
124 absl::InvalidArgumentError(
125 "number of components for extents must be 3 or 1"));
126
127 OP_REQUIRES(context,
128 inp_positions.shape().dim_size(0) ==
129 inp_features.shape().dim_size(0),
130 absl::InvalidArgumentError(
131 "first dim of inp_positions does not "
132 "match the first dim of inp_features"));
133
134 OP_REQUIRES(
135 context,
136 inp_neighbors_importance_sum.shape().dim_size(0) ==
137 inp_positions.shape().dim_size(0) ||
138 inp_neighbors_importance_sum.shape().dim_size(0) == 0,
139 absl::InvalidArgumentError(
140 "first dim of inp_neighbors_importance_sum does not "
141 "match the first dim of inp_positions"));
142
143 OP_REQUIRES(
144 context,
145 out_positions.shape().dim_size(0) ==
146 out_importance.shape().dim_size(0) ||
147 out_importance.shape().dim_size(0) == 0,
148 absl::InvalidArgumentError("first dim of out_positions does "
149 "not match the first dim of "
150 "out_importance"));
151
152 OP_REQUIRES(
153 context,
154 neighbors_importance.shape().dim_size(0) ==
155 neighbors_index.shape().dim_size(0) ||
156 neighbors_importance.shape().dim_size(0) == 0,
157 absl::InvalidArgumentError("first dim of neighbors_importance "
158 "does not match the first dim of "
159 "neighbors_index"));
160
161 OP_REQUIRES(
162 context,
163 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
164 absl::InvalidArgumentError("number of input channels in filter "
165 "and inp_features does not match"));
166
167 TensorShape out_features_shape({out_positions.shape().dim_size(0),
168 filter.shape().dim_size(4)});
169 Tensor* out_features = nullptr;
170 OP_REQUIRES_OK(context, context->allocate_output(0, out_features_shape,
171 &out_features));
172
173 std::vector<int> filter_dims({
174 int(filter.shape().dim_size(0)),
175 int(filter.shape().dim_size(1)),
176 int(filter.shape().dim_size(2)),
177 int(filter.shape().dim_size(3)),
178 int(filter.shape().dim_size(4)),
179 });
180
181 bool individual_extents = extents.shape().dim_size(0) ==
182 out_positions.shape().dim_size(0) &&
183 extents.shape().dim_size(0) > 1;
184
185 bool isotropic_extents = extents.shape().dim_size(1) == 1;
186
187 bool point_importances = out_importance.shape().dim_size(0) != 0;
188
189 bool has_neighbors_importances =
190 neighbors_importance.shape().dim_size(0) != 0;
191
192 Kernel(context, filter, out_positions, out_importance, extents, offset,
193 inp_positions, inp_features, inp_neighbors_importance_sum,
194 inp_neighbors_row_splits, neighbors_index, neighbors_importance,
195 neighbors_row_splits, filter_dims, individual_extents,
196 isotropic_extents, point_importances, has_neighbors_importances,
197 *out_features);
198 }
199
200 virtual void Kernel(tensorflow::OpKernelContext* context,
201 const tensorflow::Tensor& filter,
202 const tensorflow::Tensor& out_positions,
203 const tensorflow::Tensor& out_importance,
204 const tensorflow::Tensor& extents,
205 const tensorflow::Tensor& offset,
206 const tensorflow::Tensor& inp_positions,
207 const tensorflow::Tensor& inp_features,
208 const tensorflow::Tensor& inp_neighbors_importance_sum,
209 const tensorflow::Tensor& inp_neighbors_row_splits,
210 const tensorflow::Tensor& neighbors_index,
211 const tensorflow::Tensor& neighbors_importance,
212 const tensorflow::Tensor& neighbors_row_splits,
213 const std::vector<int>& filter_dims,
214 const bool individual_extents,
215 const bool isotropic_extents,
216 const bool point_importances,
217 const bool has_neighbors_importances,
218 tensorflow::Tensor& out_features) = 0;
219
220public:
226};
ImGuiContext * context
Definition Window.cpp:99
Definition ContinuousConvTransposeOpKernel.h:19
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition ContinuousConvTransposeOpKernel.h:224
int max_temp_mem_MB
Definition ContinuousConvTransposeOpKernel.h:225
open3d::ml::impl::InterpolationMode interpolation
Definition ContinuousConvTransposeOpKernel.h:223
bool normalize
Definition ContinuousConvTransposeOpKernel.h:222
ContinuousConvTransposeOpKernel(tensorflow::OpKernelConstruction *construction)
Definition ContinuousConvTransposeOpKernel.h:21
void Compute(tensorflow::OpKernelContext *context) override
Definition ContinuousConvTransposeOpKernel.h:58
bool align_corners
Definition ContinuousConvTransposeOpKernel.h:221
virtual void Kernel(tensorflow::OpKernelContext *context, const tensorflow::Tensor &filter, const tensorflow::Tensor &out_positions, const tensorflow::Tensor &out_importance, const tensorflow::Tensor &extents, const tensorflow::Tensor &offset, const tensorflow::Tensor &inp_positions, const tensorflow::Tensor &inp_features, const tensorflow::Tensor &inp_neighbors_importance_sum, const tensorflow::Tensor &inp_neighbors_row_splits, 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:46
Definition ContinuousConv.h:16
InterpolationMode
Definition ContinuousConvTypes.h:18
CoordinateMapping
Definition ContinuousConvTypes.h:26