Open3D (C++ API)  0.15.1
ContinuousConvBackpropFilterOpKernel.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>
35class ContinuousConvBackpropFilterOpKernel : public tensorflow::OpKernel {
36public:
38 tensorflow::OpKernelConstruction* construction)
39 : OpKernel(construction) {
40 using namespace tensorflow;
41 using namespace open3d::ml::impl;
42 OP_REQUIRES_OK(construction,
43 construction->GetAttr("align_corners", &align_corners));
44 OP_REQUIRES_OK(construction,
45 construction->GetAttr("normalize", &normalize));
46
47 std::string interpolation_str;
48 OP_REQUIRES_OK(construction, construction->GetAttr("interpolation",
49 &interpolation_str));
50
51 if (interpolation_str == "linear")
52 interpolation = InterpolationMode::LINEAR;
53 else if (interpolation_str == "linear_border")
54 interpolation = InterpolationMode::LINEAR_BORDER;
55 else
57
58 std::string mapping_str;
59 OP_REQUIRES_OK(construction, construction->GetAttr("coordinate_mapping",
60 &mapping_str));
61
62 if (mapping_str == "ball_to_cube_radial")
63 coordinate_mapping = CoordinateMapping::BALL_TO_CUBE_RADIAL;
64 else if (mapping_str == "ball_to_cube_volume_preserving")
66 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING;
67 else
68 coordinate_mapping = CoordinateMapping::IDENTITY;
69
70 OP_REQUIRES_OK(construction, construction->GetAttr("max_temp_mem_MB",
72 }
73
74 void Compute(tensorflow::OpKernelContext* context) override {
75 using namespace tensorflow;
76 static_assert(sizeof(int64) == sizeof(int64_t),
77 "int64 type is not compatible");
78 const Tensor& filter = context->input(0);
79
80 const Tensor& out_positions = context->input(1);
81 OP_REQUIRES(context,
82 out_positions.shape().dim_size(0) <=
83 std::numeric_limits<TIndex>::max(),
84 errors::InvalidArgument("Too many output points"));
85
86 const Tensor& extents = context->input(2);
87 OP_REQUIRES(context, extents.shape().dims() == 2,
88 errors::InvalidArgument("extents must be a rank 2 tensor"));
89 OP_REQUIRES(context,
90 extents.shape().dim_size(0) ==
91 out_positions.shape().dim_size(0) ||
92 extents.shape().dim_size(0) == 1,
93 errors::InvalidArgument("number of extents must match the "
94 "number of out_positions or must "
95 "be 1"));
96 OP_REQUIRES(context,
97 extents.shape().dim_size(1) == 3 ||
98 extents.shape().dim_size(1) == 1,
99 errors::InvalidArgument(
100 "number of components for extents must be 3 or 1"));
101
102 const Tensor& offset = context->input(3);
103 OP_REQUIRES(context, offset.shape().dims() == 1,
104 errors::InvalidArgument("offset must be a rank 1 tensor"));
105 OP_REQUIRES(context, offset.shape().dim_size(0) == 3,
106 errors::InvalidArgument("offset length must be 3"));
107
108 const Tensor& inp_positions = context->input(4);
109 OP_REQUIRES(context,
110 inp_positions.shape().dim_size(0) <=
111 std::numeric_limits<TIndex>::max(),
112 errors::InvalidArgument("Too many input points"));
113
114 const Tensor& inp_features = context->input(5);
115
116 const Tensor& inp_importance = context->input(6);
117
118 const Tensor& neighbors_index = context->input(7);
119
120 const Tensor& neighbors_importance = context->input(8);
121
122 const Tensor& neighbors_row_splits = context->input(9);
123
124 const Tensor& out_features_gradient = context->input(10);
125
126 OP_REQUIRES(
127 context,
128 inp_positions.shape().dim_size(0) ==
129 inp_features.shape().dim_size(0),
130 errors::InvalidArgument("first dim of inp_positions does not "
131 "match the first dim of inp_features"));
132
133 OP_REQUIRES(context,
134 inp_positions.shape().dim_size(0) ==
135 inp_importance.shape().dim_size(0) ||
136 inp_importance.shape().dim_size(0) == 0,
137 errors::InvalidArgument("first dim of inp_positions does "
138 "not match the first dim of "
139 "inp_importance"));
140
141 OP_REQUIRES(context,
142 neighbors_importance.shape().dim_size(0) ==
143 neighbors_index.shape().dim_size(0) ||
144 neighbors_importance.shape().dim_size(0) == 0,
145 errors::InvalidArgument("first dim of neighbors_importance "
146 "does not match the first dim of "
147 "neighbors_index"));
148
149 OP_REQUIRES(
150 context,
151 filter.shape().dim_size(3) == inp_features.shape().dim_size(1),
152 errors::InvalidArgument("number of input channels in filter "
153 "and inp_features does not match"));
154
155 OP_REQUIRES(context,
156 out_features_gradient.shape().dim_size(0) ==
157 out_positions.shape().dim_size(0),
158 errors::InvalidArgument("first dim of out_positions, does "
159 "not match the first dim of "
160 "out_features_gradient"));
161
162 TensorShape filter_backprop_shape(filter.shape());
163 Tensor* filter_backprop = nullptr;
164 OP_REQUIRES_OK(context,
165 context->allocate_output(0, filter_backprop_shape,
166 &filter_backprop));
167
168 std::vector<int> filter_dims({
169 int(filter.shape().dim_size(0)),
170 int(filter.shape().dim_size(1)),
171 int(filter.shape().dim_size(2)),
172 int(filter.shape().dim_size(3)),
173 int(filter.shape().dim_size(4)),
174 });
175
176 bool individual_extents = extents.shape().dim_size(0) ==
177 out_positions.shape().dim_size(0) &&
178 extents.shape().dim_size(0) > 1;
179
180 bool isotropic_extents = extents.shape().dim_size(1) == 1;
181
182 bool point_importances = inp_importance.shape().dim_size(0) != 0;
183
184 bool has_neighbors_importances =
185 neighbors_importance.shape().dim_size(0) != 0;
186
187 Kernel(context, filter, out_positions, extents, offset, inp_positions,
188 inp_features, inp_importance, neighbors_index,
189 neighbors_importance, neighbors_row_splits,
190 out_features_gradient, filter_dims, individual_extents,
191 isotropic_extents, point_importances, has_neighbors_importances,
192 *filter_backprop);
193 }
194
195 virtual void Kernel(tensorflow::OpKernelContext* context,
196 const tensorflow::Tensor& filter,
197 const tensorflow::Tensor& out_positions,
198 const tensorflow::Tensor& extents,
199 const tensorflow::Tensor& offset,
200 const tensorflow::Tensor& inp_positions,
201 const tensorflow::Tensor& inp_features,
202 const tensorflow::Tensor& inp_importance,
203 const tensorflow::Tensor& neighbors_index,
204 const tensorflow::Tensor& neighbors_importance,
205 const tensorflow::Tensor& neighbors_row_splits,
206 const tensorflow::Tensor& out_features_gradient,
207 const std::vector<int>& filter_dims,
208 const bool individual_extents,
209 const bool isotropic_extents,
210 const bool point_importances,
211 const bool has_neighbors_importances,
212 tensorflow::Tensor& filter_backprop) = 0;
213
214public:
220};
ImGuiContext * context
Definition: Window.cpp:95
Definition: ContinuousConvBackpropFilterOpKernel.h:35
bool align_corners
Definition: ContinuousConvBackpropFilterOpKernel.h:215
int max_temp_mem_MB
Definition: ContinuousConvBackpropFilterOpKernel.h:219
open3d::ml::impl::CoordinateMapping coordinate_mapping
Definition: ContinuousConvBackpropFilterOpKernel.h:218
ContinuousConvBackpropFilterOpKernel(tensorflow::OpKernelConstruction *construction)
Definition: ContinuousConvBackpropFilterOpKernel.h:37
bool normalize
Definition: ContinuousConvBackpropFilterOpKernel.h:216
void Compute(tensorflow::OpKernelContext *context) override
Definition: ContinuousConvBackpropFilterOpKernel.h:74
open3d::ml::impl::InterpolationMode interpolation
Definition: ContinuousConvBackpropFilterOpKernel.h:217
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: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