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