Open3D (C++ API)  0.15.1
ContinuousConvTransposeBackpropFilterOpKernel.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
30#include "tensorflow/core/framework/op.h"
31#include "tensorflow/core/framework/op_kernel.h"
32#include "tensorflow/core/lib/core/errors.h"
33
34template <class TIndex>
36 : public tensorflow::OpKernel {
37public:
39 tensorflow::OpKernelConstruction* construction)
40 : OpKernel(construction) {
41 using namespace tensorflow;
42 using namespace open3d::ml::impl;
43 OP_REQUIRES_OK(construction,
44 construction->GetAttr("align_corners", &align_corners));
45 OP_REQUIRES_OK(construction,
46 construction->GetAttr("normalize", &normalize));
47
48 std::string interpolation_str;
49 OP_REQUIRES_OK(construction, construction->GetAttr("interpolation",
50 &interpolation_str));
51
52 if (interpolation_str == "linear")
53 interpolation = InterpolationMode::LINEAR;
54 else if (interpolation_str == "linear_border")
55 interpolation = InterpolationMode::LINEAR_BORDER;
56 else
58
59 std::string mapping_str;
60 OP_REQUIRES_OK(construction, construction->GetAttr("coordinate_mapping",
61 &mapping_str));
62
63 if (mapping_str == "ball_to_cube_radial")
64 coordinate_mapping = CoordinateMapping::BALL_TO_CUBE_RADIAL;
65 else if (mapping_str == "ball_to_cube_volume_preserving")
67 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
68 else
69 coordinate_mapping = CoordinateMapping::IDENTITY;
70
71 OP_REQUIRES_OK(construction, construction->GetAttr("max_temp_mem_MB",
73 }
74
75 void Compute(tensorflow::OpKernelContext* context) override {
76 using namespace tensorflow;
77 static_assert(sizeof(int64) == sizeof(int64_t),
78 "int64 type is not compatible");
79 const Tensor& filter = context->input(0);
80
81 const Tensor& out_positions = context->input(1);
82 OP_REQUIRES(context,
83 out_positions.shape().dim_size(0) <=
84 std::numeric_limits<TIndex>::max(),
85 errors::InvalidArgument("Too many output points"));
86
87 const Tensor& out_importance = context->input(2);
88 OP_REQUIRES(context,
89 out_importance.shape().dim_size(0) == 0 ||
90 out_importance.shape().dim_size(0) ==
91 out_positions.shape().dim_size(0),
92 errors::InvalidArgument("length of out_importance must "
93 "match the number of output points "
94 "or must be 0"));
95
96 const Tensor& extents = context->input(3);
97
98 const Tensor& offset = context->input(4);
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"));
103
104 const Tensor& inp_positions = context->input(5);
105 OP_REQUIRES(context,
106 inp_positions.shape().dim_size(0) <=
107 std::numeric_limits<TIndex>::max(),
108 errors::InvalidArgument("Too many input points"));
109
110 const Tensor& inp_features = context->input(6);
111
112 const Tensor& inp_neighbors_importance_sum = context->input(7);
113
114 const Tensor& inp_neighbors_row_splits = context->input(8);
115
116 const Tensor& neighbors_index = context->input(9);
117
118 const Tensor& neighbors_importance = context->input(10);
119
120 const Tensor& neighbors_row_splits = context->input(11);
121
122 const Tensor& out_features_gradient = context->input(12);
123
124 OP_REQUIRES(context, extents.shape().dims() == 2,
125 errors::InvalidArgument("extents must be a rank 2 tensor"));
126 OP_REQUIRES(context,
127 extents.shape().dim_size(0) ==
128 inp_positions.shape().dim_size(0) ||
129 extents.shape().dim_size(0) == 1,
130 errors::InvalidArgument("number of extents must match the "
131 "number of inp_positions or must "
132 "be 1"));
133 OP_REQUIRES(context,
134 extents.shape().dim_size(1) == 3 ||
135 extents.shape().dim_size(1) == 1,
136 errors::InvalidArgument(
137 "number of components for extents must be 3 or 1"));
138
139 OP_REQUIRES(
140 context,
141 inp_positions.shape().dim_size(0) ==
142 inp_features.shape().dim_size(0),
143 errors::InvalidArgument("first dim of inp_positions does not "
144 "match the first dim of inp_features"));
145
146 OP_REQUIRES(
147 context,
148 inp_neighbors_importance_sum.shape().dim_size(0) ==
149 inp_positions.shape().dim_size(0) ||
150 inp_neighbors_importance_sum.shape().dim_size(0) == 0,
151 errors::InvalidArgument(
152 "first dim of inp_neighbors_importance_sum does not "
153 "match the first dim of inp_positions",
154 inp_neighbors_importance_sum.shape().dim_size(0), " ",
155 inp_positions.shape().dim_size(0)));
156
157 OP_REQUIRES(context,
158 out_positions.shape().dim_size(0) ==
159 out_importance.shape().dim_size(0) ||
160 out_importance.shape().dim_size(0) == 0,
161 errors::InvalidArgument("first dim of out_positions does "
162 "not match the first dim of "
163 "out_importance"));
164
165 OP_REQUIRES(context,
166 neighbors_importance.shape().dim_size(0) ==
167 neighbors_index.shape().dim_size(0) ||
168 neighbors_importance.shape().dim_size(0) == 0,
169 errors::InvalidArgument("first dim of neighbors_importance "
170 "does not match the first dim of "
171 "neighbors_index"));
172
173 OP_REQUIRES(
174 context,
175 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
176 errors::InvalidArgument("number of input channels in filter "
177 "and inp_features does not match"));
178
179 OP_REQUIRES(context,
180 out_features_gradient.shape().dim_size(0) ==
181 out_positions.shape().dim_size(0),
182 errors::InvalidArgument("first dim of out_positions, does "
183 "not match the first dim of "
184 "out_features_gradient"));
185
186 TensorShape filter_backprop_shape(filter.shape());
187 Tensor* filter_backprop = nullptr;
188 OP_REQUIRES_OK(context,
189 context->allocate_output(0, filter_backprop_shape,
190 &filter_backprop));
191
192 std::vector<int> filter_dims({
193 int(filter.shape().dim_size(0)),
194 int(filter.shape().dim_size(1)),
195 int(filter.shape().dim_size(2)),
196 int(filter.shape().dim_size(3)),
197 int(filter.shape().dim_size(4)),
198 });
199
200 bool individual_extents = extents.shape().dim_size(0) ==
201 out_positions.shape().dim_size(0) &&
202 extents.shape().dim_size(0) > 1;
203
204 bool isotropic_extents = extents.shape().dim_size(1) == 1;
205
206 bool point_importances = out_importance.shape().dim_size(0) != 0;
207
208 bool has_neighbors_importances =
209 neighbors_importance.shape().dim_size(0) != 0;
210
211 Kernel(context, filter, out_positions, out_importance, extents, offset,
212 inp_positions, inp_features, inp_neighbors_importance_sum,
213 inp_neighbors_row_splits, neighbors_index, neighbors_importance,
214 neighbors_row_splits, out_features_gradient, filter_dims,
215 individual_extents, isotropic_extents, point_importances,
216 has_neighbors_importances, *filter_backprop);
217 }
218
219 virtual void Kernel(tensorflow::OpKernelContext* context,
220 const tensorflow::Tensor& filter,
221 const tensorflow::Tensor& out_positions,
222 const tensorflow::Tensor& out_importance,
223 const tensorflow::Tensor& extents,
224 const tensorflow::Tensor& offset,
225 const tensorflow::Tensor& inp_positions,
226 const tensorflow::Tensor& inp_features,
227 const tensorflow::Tensor& inp_neighbors_importance_sum,
228 const tensorflow::Tensor& inp_neighbors_row_splits,
229 const tensorflow::Tensor& neighbors_index,
230 const tensorflow::Tensor& neighbors_importance,
231 const tensorflow::Tensor& neighbors_row_splits,
232 const tensorflow::Tensor& out_features_gradient,
233 const std::vector<int>& filter_dims,
234 const bool individual_extents,
235 const bool isotropic_extents,
236 const bool point_importances,
237 const bool has_neighbors_importances,
238 tensorflow::Tensor& filter_backprop) = 0;
239
240public:
246};
ImGuiContext * context
Definition: Window.cpp:95
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:36
ContinuousConvTransposeBackpropFilterOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:38
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:241
void Compute(tensorflow::OpKernelContext *context) override
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:75
open3d::ml::impl::InterpolationMode interpolation
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:243
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:244
bool normalize
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:242
int max_temp_mem_MB
Definition: ContinuousConvTransposeBackpropFilterOpKernel.h:245
int offset
Definition: FilePCD.cpp:64
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:493
Definition: ContinuousConv.h:35
InterpolationMode
Definition: ContinuousConvTypes.h:37
@ NEAREST_NEIGHBOR
Definition: VoxelPooling.h:40
CoordinateMapping
Definition: ContinuousConvTypes.h:45