Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
ContinuousConvTransposeBackpropFilterOpKernel.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>
20 : public tensorflow::OpKernel {
21public:
23 tensorflow::OpKernelConstruction* construction)
24 : OpKernel(construction) {
25 using namespace tensorflow;
26 using namespace open3d::ml::impl;
27 OP_REQUIRES_OK(construction,
28 construction->GetAttr("align_corners", &align_corners));
29 OP_REQUIRES_OK(construction,
30 construction->GetAttr("normalize", &normalize));
31
32 std::string interpolation_str;
33 OP_REQUIRES_OK(construction, construction->GetAttr("interpolation",
34 &interpolation_str));
35
36 if (interpolation_str == "linear")
37 interpolation = InterpolationMode::LINEAR;
38 else if (interpolation_str == "linear_border")
39 interpolation = InterpolationMode::LINEAR_BORDER;
40 else
41 interpolation = InterpolationMode::NEAREST_NEIGHBOR;
42
43 std::string mapping_str;
44 OP_REQUIRES_OK(construction, construction->GetAttr("coordinate_mapping",
45 &mapping_str));
46
47 if (mapping_str == "ball_to_cube_radial")
48 coordinate_mapping = CoordinateMapping::BALL_TO_CUBE_RADIAL;
49 else if (mapping_str == "ball_to_cube_volume_preserving")
51 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
52 else
53 coordinate_mapping = CoordinateMapping::IDENTITY;
54
55 OP_REQUIRES_OK(construction, construction->GetAttr("max_temp_mem_MB",
57 }
58
59 void Compute(tensorflow::OpKernelContext* context) override {
60 using namespace tensorflow;
61 static_assert(sizeof(int64_t) == sizeof(int64_t),
62 "int64_t type is not compatible");
63 const Tensor& filter = context->input(0);
64
65 const Tensor& out_positions = context->input(1);
66 OP_REQUIRES(context,
67 out_positions.shape().dim_size(0) <=
68 std::numeric_limits<TIndex>::max(),
69 absl::InvalidArgumentError("Too many output points"));
70
71 const Tensor& out_importance = context->input(2);
72 OP_REQUIRES(
73 context,
74 out_importance.shape().dim_size(0) == 0 ||
75 out_importance.shape().dim_size(0) ==
76 out_positions.shape().dim_size(0),
77 absl::InvalidArgumentError("length of out_importance must "
78 "match the number of output points "
79 "or must be 0"));
80
81 const Tensor& extents = context->input(3);
82
83 const Tensor& offset = context->input(4);
84 OP_REQUIRES(
85 context, offset.shape().dims() == 1,
86 absl::InvalidArgumentError("offset must be a rank 1 tensor"));
87 OP_REQUIRES(context, offset.shape().dim_size(0) == 3,
88 absl::InvalidArgumentError("offset length must be 3"));
89
90 const Tensor& inp_positions = context->input(5);
91 OP_REQUIRES(context,
92 inp_positions.shape().dim_size(0) <=
93 std::numeric_limits<TIndex>::max(),
94 absl::InvalidArgumentError("Too many input points"));
95
96 const Tensor& inp_features = context->input(6);
97
98 const Tensor& inp_neighbors_importance_sum = context->input(7);
99
100 const Tensor& inp_neighbors_row_splits = context->input(8);
101
102 const Tensor& neighbors_index = context->input(9);
103
104 const Tensor& neighbors_importance = context->input(10);
105
106 const Tensor& neighbors_row_splits = context->input(11);
107
108 const Tensor& out_features_gradient = 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 OP_REQUIRES(context,
168 out_features_gradient.shape().dim_size(0) ==
169 out_positions.shape().dim_size(0),
170 absl::InvalidArgumentError(
171 std::string("first dim of out_positions, does "
172 "not match the first dim of "
173 "out_features_gradient")));
174
175 TensorShape filter_backprop_shape(filter.shape());
176 Tensor* filter_backprop = nullptr;
177 OP_REQUIRES_OK(context,
178 context->allocate_output(0, filter_backprop_shape,
179 &filter_backprop));
180
181 std::vector<int> filter_dims({
182 int(filter.shape().dim_size(0)),
183 int(filter.shape().dim_size(1)),
184 int(filter.shape().dim_size(2)),
185 int(filter.shape().dim_size(3)),
186 int(filter.shape().dim_size(4)),
187 });
188
189 bool individual_extents = extents.shape().dim_size(0) ==
190 out_positions.shape().dim_size(0) &&
191 extents.shape().dim_size(0) > 1;
192
193 bool isotropic_extents = extents.shape().dim_size(1) == 1;
194
195 bool point_importances = out_importance.shape().dim_size(0) != 0;
196
197 bool has_neighbors_importances =
198 neighbors_importance.shape().dim_size(0) != 0;
199
200 Kernel(context, filter, out_positions, out_importance, extents, offset,
201 inp_positions, inp_features, inp_neighbors_importance_sum,
202 inp_neighbors_row_splits, neighbors_index, neighbors_importance,
203 neighbors_row_splits, out_features_gradient, filter_dims,
204 individual_extents, isotropic_extents, point_importances,
205 has_neighbors_importances, *filter_backprop);
206 }
207
208 virtual void Kernel(tensorflow::OpKernelContext* context,
209 const tensorflow::Tensor& filter,
210 const tensorflow::Tensor& out_positions,
211 const tensorflow::Tensor& out_importance,
212 const tensorflow::Tensor& extents,
213 const tensorflow::Tensor& offset,
214 const tensorflow::Tensor& inp_positions,
215 const tensorflow::Tensor& inp_features,
216 const tensorflow::Tensor& inp_neighbors_importance_sum,
217 const tensorflow::Tensor& inp_neighbors_row_splits,
218 const tensorflow::Tensor& neighbors_index,
219 const tensorflow::Tensor& neighbors_importance,
220 const tensorflow::Tensor& neighbors_row_splits,
221 const tensorflow::Tensor& out_features_gradient,
222 const std::vector<int>& filter_dims,
223 const bool individual_extents,
224 const bool isotropic_extents,
225 const bool point_importances,
226 const bool has_neighbors_importances,
227 tensorflow::Tensor& filter_backprop) = 0;
228
229public:
235};
ImGuiContext * context
Definition Window.cpp:99
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:20
ContinuousConvTransposeBackpropFilterOpKernel(tensorflow::OpKernelConstruction *construction)
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:22
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 tensorflow::Tensor &out_features_gradient, 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 &filter_backprop)=0
bool align_corners
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:230
void Compute(tensorflow::OpKernelContext *context) override
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:59
open3d::ml::impl::InterpolationMode interpolation
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:232
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:233
bool normalize
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:231
int max_temp_mem_MB
Definition ContinuousConvTransposeBackpropFilterOpKernel.h:234
int offset
Definition FilePCD.cpp:46
Definition ContinuousConv.h:16
InterpolationMode
Definition ContinuousConvTypes.h:18
CoordinateMapping
Definition ContinuousConvTypes.h:26