Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
ContinuousConvBackpropFilterOpKernel.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 ContinuousConvBackpropFilterOpKernel : 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 const Tensor& out_features_gradient = context->input(10);
112
113 OP_REQUIRES(context,
114 inp_positions.shape().dim_size(0) ==
115 inp_features.shape().dim_size(0),
116 absl::InvalidArgumentError(
117 "first dim of inp_positions does not "
118 "match the first dim of inp_features"));
119
120 OP_REQUIRES(
121 context,
122 inp_positions.shape().dim_size(0) ==
123 inp_importance.shape().dim_size(0) ||
124 inp_importance.shape().dim_size(0) == 0,
125 absl::InvalidArgumentError("first dim of inp_positions does "
126 "not match the first dim of "
127 "inp_importance"));
128
129 OP_REQUIRES(
130 context,
131 neighbors_importance.shape().dim_size(0) ==
132 neighbors_index.shape().dim_size(0) ||
133 neighbors_importance.shape().dim_size(0) == 0,
134 absl::InvalidArgumentError("first dim of neighbors_importance "
135 "does not match the first dim of "
136 "neighbors_index"));
137
138 OP_REQUIRES(
139 context,
140 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
141 absl::InvalidArgumentError("number of input channels in filter "
142 "and inp_features does not match"));
143
144 OP_REQUIRES(context,
145 out_features_gradient.shape().dim_size(0) ==
146 out_positions.shape().dim_size(0),
147 absl::InvalidArgumentError(
148 std::string("first dim of out_positions, does "
149 "not match the first dim of "
150 "out_features_gradient")));
151
152 TensorShape filter_backprop_shape(filter.shape());
153 Tensor* filter_backprop = nullptr;
154 OP_REQUIRES_OK(context,
155 context->allocate_output(0, filter_backprop_shape,
156 &filter_backprop));
157
158 std::vector<int> filter_dims({
159 int(filter.shape().dim_size(0)),
160 int(filter.shape().dim_size(1)),
161 int(filter.shape().dim_size(2)),
162 int(filter.shape().dim_size(3)),
163 int(filter.shape().dim_size(4)),
164 });
165
166 bool individual_extents = extents.shape().dim_size(0) ==
167 out_positions.shape().dim_size(0) &&
168 extents.shape().dim_size(0) > 1;
169
170 bool isotropic_extents = extents.shape().dim_size(1) == 1;
171
172 bool point_importances = inp_importance.shape().dim_size(0) != 0;
173
174 bool has_neighbors_importances =
175 neighbors_importance.shape().dim_size(0) != 0;
176
177 Kernel(context, filter, out_positions, extents, offset, inp_positions,
178 inp_features, inp_importance, neighbors_index,
179 neighbors_importance, neighbors_row_splits,
180 out_features_gradient, filter_dims, individual_extents,
181 isotropic_extents, point_importances, has_neighbors_importances,
182 *filter_backprop);
183 }
184
185 virtual void Kernel(tensorflow::OpKernelContext* context,
186 const tensorflow::Tensor& filter,
187 const tensorflow::Tensor& out_positions,
188 const tensorflow::Tensor& extents,
189 const tensorflow::Tensor& offset,
190 const tensorflow::Tensor& inp_positions,
191 const tensorflow::Tensor& inp_features,
192 const tensorflow::Tensor& inp_importance,
193 const tensorflow::Tensor& neighbors_index,
194 const tensorflow::Tensor& neighbors_importance,
195 const tensorflow::Tensor& neighbors_row_splits,
196 const tensorflow::Tensor& out_features_gradient,
197 const std::vector<int>& filter_dims,
198 const bool individual_extents,
199 const bool isotropic_extents,
200 const bool point_importances,
201 const bool has_neighbors_importances,
202 tensorflow::Tensor& filter_backprop) = 0;
203
204public:
210};
ImGuiContext * context
Definition Window.cpp:99
Definition ContinuousConvBackpropFilterOpKernel.h:19
bool align_corners
Definition ContinuousConvBackpropFilterOpKernel.h:205
int max_temp_mem_MB
Definition ContinuousConvBackpropFilterOpKernel.h:209
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition ContinuousConvBackpropFilterOpKernel.h:208
ContinuousConvBackpropFilterOpKernel(tensorflow::OpKernelConstruction *construction)
Definition ContinuousConvBackpropFilterOpKernel.h:21
bool normalize
Definition ContinuousConvBackpropFilterOpKernel.h:206
void Compute(tensorflow::OpKernelContext *context) override
Definition ContinuousConvBackpropFilterOpKernel.h:58
open3d::ml::impl::InterpolationMode interpolation
Definition ContinuousConvBackpropFilterOpKernel.h:207
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 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
int offset
Definition FilePCD.cpp:46
Definition ContinuousConv.h:16
InterpolationMode
Definition ContinuousConvTypes.h:18
CoordinateMapping
Definition ContinuousConvTypes.h:26