10 #include <tbb/parallel_for.h>
20 template <
class TFeat,
27 bool INDIVIDUAL_EXTENT,
28 bool ISOTROPIC_EXTENT,
32 const std::vector<int>& filter_dims,
35 const TReal* out_positions,
36 const TFeat* out_importance,
38 const TReal* inp_positions,
39 const TFeat* inp_features,
40 const TFeat* inp_neighbors_importance_sum,
41 const int64_t* inp_neighbors_row_splits,
42 size_t neighbors_index_size,
43 const TIndex* neighbors_index,
44 const TFeat* neighbors_importance,
45 const int64_t* neighbors_row_splits,
47 const TReal* offsets) {
48 const bool NEIGHBORS_IMPORTANCE = inp_neighbors_importance_sum;
50 typedef Eigen::Array<TReal, VECSIZE, 1> Vec_t;
52 InterpolationVec_t interpolation;
54 const int in_channels = filter_dims[filter_dims.size() - 2];
55 const int out_channels = filter_dims[filter_dims.size() - 1];
57 int spatial_filter_size = 1;
58 for (
int i = 0; i < 3; ++i) spatial_filter_size *= filter_dims[i];
59 Eigen::Array<int, 3, 1> filter_size_xyz(filter_dims[2], filter_dims[1],
62 memset(out_features, 0,
sizeof(TOut) * num_out * out_channels);
65 tbb::blocked_range<size_t>(0, num_out, 32),
66 [&](
const tbb::blocked_range<size_t>& r) {
67 int range_length = r.end() - r.begin();
69 Eigen::Matrix<TFeat, Eigen::Dynamic, Eigen::Dynamic>
B(
70 in_channels * spatial_filter_size, range_length);
73 typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
74 Matrix infeat(
VECSIZE, in_channels);
76 Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
79 Eigen::Array<TReal, VECSIZE, 3> inv_extents;
80 if (INDIVIDUAL_EXTENT ==
false) {
81 if (ISOTROPIC_EXTENT) {
82 inv_extents = 1 / extents[0];
84 inv_extents.col(0) = 1 / extents[0];
85 inv_extents.col(1) = 1 / extents[1];
86 inv_extents.col(2) = 1 / extents[2];
90 for (
size_t out_idx = r.begin(); out_idx != r.end();
92 const int out_col = out_idx - r.begin();
93 const size_t neighbor_start = neighbors_row_splits[out_idx];
94 const size_t neighbor_end =
95 (out_idx + 1 < num_out
96 ? neighbors_row_splits[out_idx + 1]
97 : neighbors_index_size);
99 typename InterpolationVec_t::Weight_t interp_weights;
100 typename InterpolationVec_t::Idx_t interp_indices;
102 int vec_valid_count = 0;
110 for (
size_t n = neighbor_start; n < neighbor_end; ++n) {
111 const size_t inp_idx = neighbors_index[n];
113 const int i = vec_valid_count;
114 x(i) = out_positions[out_idx * 3 + 0] -
115 inp_positions[inp_idx * 3 + 0];
116 y(i) = out_positions[out_idx * 3 + 1] -
117 inp_positions[inp_idx * 3 + 1];
118 z(i) = out_positions[out_idx * 3 + 2] -
119 inp_positions[inp_idx * 3 + 2];
121 if (INDIVIDUAL_EXTENT) {
122 if (ISOTROPIC_EXTENT) {
123 inv_extents.row(i) = 1 / extents[inp_idx];
126 1 / extents[3 * inp_idx + 0];
128 1 / extents[3 * inp_idx + 1];
130 1 / extents[3 * inp_idx + 2];
134 TFeat n_importance = NEIGHBORS_IMPORTANCE
135 ? neighbors_importance[n]
137 for (
int ic = 0; ic < in_channels; ++ic)
139 inp_features[inp_idx * in_channels + ic] *
144 if (NEIGHBORS_IMPORTANCE) {
145 if (inp_neighbors_importance_sum[inp_idx] !=
147 normalizer /= inp_neighbors_importance_sum
150 size_t num_inp_neighbors;
151 const size_t inp_neighbor_start =
152 inp_neighbors_row_splits[inp_idx];
153 const size_t inp_neighbor_end =
154 inp_neighbors_row_splits[inp_idx + 1];
156 inp_neighbor_end - inp_neighbor_start;
157 if (num_inp_neighbors > 0)
158 normalizer /= TFeat(num_inp_neighbors);
160 for (
int ic = 0; ic < in_channels; ++ic)
161 infeat(i, ic) *= normalizer;
165 if (vec_valid_count ==
VECSIZE ||
166 n + 1 == neighbor_end) {
167 ComputeFilterCoordinates<ALIGN_CORNERS, MAPPING>(
168 x, y, z, filter_size_xyz, inv_extents,
170 interpolation.Interpolate(
171 interp_weights, interp_indices, x, y, z,
172 filter_size_xyz, in_channels);
173 for (
int k = 0; k < vec_valid_count; ++k) {
174 for (
int j = 0; j < InterpolationVec_t::Size();
176 for (
int ic = 0; ic < in_channels; ++ic)
177 B(interp_indices(j, k) + ic, out_col) +=
178 TFeat(interp_weights(j, k)) *
188 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
190 A(filter, out_channels,
191 spatial_filter_size * in_channels);
192 Eigen::Map<Eigen::Matrix<TOut, Eigen::Dynamic, Eigen::Dynamic>>
193 C(out_features + (r.begin() * out_channels),
194 out_channels, range_length);
196 C = (A *
B).
template cast<TOut>();
197 if (out_importance) {
198 for (
int i = 0; i < range_length; ++i)
199 C.col(i) *= TOut(out_importance[r.begin() + i]);
285 template <
class TFeat,
class TOut,
class TReal,
class TIndex>
287 const std::vector<int>& filter_dims,
290 const TReal* out_positions,
291 const TFeat* out_importance,
293 const TReal* inp_positions,
294 const TFeat* inp_features,
295 const TFeat* inp_neighbors_importance_sum,
296 const int64_t* inp_neighbors_row_splits,
297 size_t neighbors_index_size,
298 const TIndex* neighbors_index,
299 const TFeat* neighbors_importance,
300 const int64_t* neighbors_row_splits,
301 const TReal* extents,
302 const TReal* offsets,
306 bool individual_extent,
307 bool isotropic_extent,
309 #define FN_PARAMETERS \
310 out_features, filter_dims, filter, num_out, out_positions, out_importance, \
311 num_inp, inp_positions, inp_features, \
312 inp_neighbors_importance_sum, inp_neighbors_row_splits, \
313 neighbors_index_size, neighbors_index, neighbors_importance, \
314 neighbors_row_splits, extents, offsets
316 #define CALL_TEMPLATE(INTERPOLATION, MAPPING, ALIGN_CORNERS, \
317 INDIVIDUAL_EXTENT, ISOTROPIC_EXTENT, NORMALIZE) \
318 if (INTERPOLATION == interpolation && MAPPING == coordinate_mapping && \
319 ALIGN_CORNERS == align_corners && \
320 INDIVIDUAL_EXTENT == individual_extent && \
321 ISOTROPIC_EXTENT == isotropic_extent && NORMALIZE == normalize) \
322 _CConvTransposeComputeFeaturesCPU<TFeat, TOut, TReal, TIndex, \
323 INTERPOLATION, MAPPING, \
324 ALIGN_CORNERS, INDIVIDUAL_EXTENT, \
325 ISOTROPIC_EXTENT, NORMALIZE>( \
328 #define CALL_TEMPLATE2(INTERPOLATION, MAPPING) \
329 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, true, true) \
330 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, true, false) \
331 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, false, true) \
332 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, false, false) \
333 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, true, true) \
334 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, true, false) \
335 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, false, true) \
336 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, false, false) \
337 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, true, true) \
338 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, true, false) \
339 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, false, true) \
340 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, false, false) \
341 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, true, true) \
342 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, true, false) \
343 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, false, true) \
344 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, false, false)
346 #define CALL_TEMPLATE3(INTERPOLATION) \
347 CALL_TEMPLATE2(INTERPOLATION, CoordinateMapping::BALL_TO_CUBE_RADIAL) \
348 CALL_TEMPLATE2(INTERPOLATION, \
349 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING) \
350 CALL_TEMPLATE2(INTERPOLATION, CoordinateMapping::IDENTITY)
352 #define CALL_TEMPLATE4 \
353 CALL_TEMPLATE3(InterpolationMode::LINEAR) \
354 CALL_TEMPLATE3(InterpolationMode::LINEAR_BORDER) \
355 CALL_TEMPLATE3(InterpolationMode::NEAREST_NEIGHBOR)
360 #undef CALL_TEMPLATE2
361 #undef CALL_TEMPLATE3
362 #undef CALL_TEMPLATE4
Eigen::Matrix3d B
Definition: PointCloudPlanarPatchDetection.cpp:512
InterpolationMode
Definition: ContinuousConvTypes.h:18
void _CConvTransposeComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, const TReal *out_positions, const TFeat *out_importance, size_t num_inp, const TReal *inp_positions, const TFeat *inp_features, const TFeat *inp_neighbors_importance_sum, const int64_t *inp_neighbors_row_splits, size_t neighbors_index_size, const TIndex *neighbors_index, const TFeat *neighbors_importance, const int64_t *neighbors_row_splits, const TReal *extents, const TReal *offsets)
Definition: ContinuousConvTranspose.h:30
void CConvTransposeComputeFeaturesCPU(TOut *out_features, const std::vector< int > &filter_dims, const TFeat *filter, size_t num_out, const TReal *out_positions, const TFeat *out_importance, size_t num_inp, const TReal *inp_positions, const TFeat *inp_features, const TFeat *inp_neighbors_importance_sum, const int64_t *inp_neighbors_row_splits, size_t neighbors_index_size, const TIndex *neighbors_index, const TFeat *neighbors_importance, const int64_t *neighbors_row_splits, const TReal *extents, const TReal *offsets, InterpolationMode interpolation, CoordinateMapping coordinate_mapping, bool align_corners, bool individual_extent, bool isotropic_extent, bool normalize)
Definition: ContinuousConvTranspose.h:286
CoordinateMapping
Definition: ContinuousConvTypes.h:26
Definition: PinholeCameraIntrinsic.cpp:16
Class for computing interpolation weights.
Definition: CoordinateTransformation.h:185