29 #include <tbb/parallel_for.h> 39 template <
class TFeat,
46 bool INDIVIDUAL_EXTENT,
47 bool ISOTROPIC_EXTENT,
51 const std::vector<int>& filter_dims,
54 const TReal* out_positions,
55 const TFeat* out_importance,
57 const TReal* inp_positions,
58 const TFeat* inp_features,
59 const TFeat* inp_neighbors_importance_sum,
60 const int64_t* inp_neighbors_row_splits,
61 size_t neighbors_index_size,
62 const TIndex* neighbors_index,
63 const TFeat* neighbors_importance,
64 const int64_t* neighbors_row_splits,
66 const TReal* offsets) {
67 const bool NEIGHBORS_IMPORTANCE = inp_neighbors_importance_sum;
69 typedef Eigen::Array<TReal, VECSIZE, 1> Vec_t;
71 InterpolationVec_t interpolation;
73 const int in_channels = filter_dims[filter_dims.size() - 2];
74 const int out_channels = filter_dims[filter_dims.size() - 1];
76 int spatial_filter_size = 1;
77 for (
int i = 0; i < 3; ++i) spatial_filter_size *= filter_dims[i];
78 Eigen::Array<int, 3, 1> filter_size_xyz(filter_dims[2], filter_dims[1],
81 memset(out_features, 0,
sizeof(TOut) * num_out * out_channels);
84 tbb::blocked_range<size_t>(0, num_out, 32),
85 [&](
const tbb::blocked_range<size_t>& r) {
86 int range_length = r.end() - r.begin();
88 Eigen::Matrix<TFeat, Eigen::Dynamic, Eigen::Dynamic> B(
89 in_channels * spatial_filter_size, range_length);
92 typedef Eigen::Array<TFeat, VECSIZE, Eigen::Dynamic> Matrix;
93 Matrix infeat(VECSIZE, in_channels);
95 Eigen::Array<TReal, 3, 1> offsets_(offsets[0], offsets[1],
98 Eigen::Array<TReal, VECSIZE, 3> inv_extents;
99 if (INDIVIDUAL_EXTENT ==
false) {
100 if (ISOTROPIC_EXTENT) {
101 inv_extents = 1 / extents[0];
103 inv_extents.col(0) = 1 / extents[0];
104 inv_extents.col(1) = 1 / extents[1];
105 inv_extents.col(2) = 1 / extents[2];
109 for (
size_t out_idx = r.begin(); out_idx != r.end();
111 const int out_col = out_idx - r.begin();
112 const size_t neighbor_start = neighbors_row_splits[out_idx];
113 const size_t neighbor_end =
114 (out_idx + 1 < num_out
115 ? neighbors_row_splits[out_idx + 1]
116 : neighbors_index_size);
118 typename InterpolationVec_t::Weight_t interp_weights;
119 typename InterpolationVec_t::Idx_t interp_indices;
121 int vec_valid_count = 0;
129 for (
size_t n = neighbor_start; n < neighbor_end; ++n) {
130 const size_t inp_idx = neighbors_index[n];
132 const int i = vec_valid_count;
133 x(i) = out_positions[out_idx * 3 + 0] -
134 inp_positions[inp_idx * 3 + 0];
135 y(i) = out_positions[out_idx * 3 + 1] -
136 inp_positions[inp_idx * 3 + 1];
137 z(i) = out_positions[out_idx * 3 + 2] -
138 inp_positions[inp_idx * 3 + 2];
140 if (INDIVIDUAL_EXTENT) {
141 if (ISOTROPIC_EXTENT) {
142 inv_extents.row(i) = 1 / extents[inp_idx];
145 1 / extents[3 * inp_idx + 0];
147 1 / extents[3 * inp_idx + 1];
149 1 / extents[3 * inp_idx + 2];
153 TFeat n_importance = NEIGHBORS_IMPORTANCE
154 ? neighbors_importance[n]
156 for (
int ic = 0; ic < in_channels; ++ic)
158 inp_features[inp_idx * in_channels + ic] *
163 if (NEIGHBORS_IMPORTANCE) {
164 if (inp_neighbors_importance_sum[inp_idx] !=
166 normalizer /= inp_neighbors_importance_sum
169 size_t num_inp_neighbors;
170 const size_t inp_neighbor_start =
171 inp_neighbors_row_splits[inp_idx];
172 const size_t inp_neighbor_end =
173 inp_neighbors_row_splits[inp_idx + 1];
175 inp_neighbor_end - inp_neighbor_start;
176 if (num_inp_neighbors > 0)
177 normalizer /= TFeat(num_inp_neighbors);
179 for (
int ic = 0; ic < in_channels; ++ic)
180 infeat(i, ic) *= normalizer;
184 if (vec_valid_count == VECSIZE ||
185 n + 1 == neighbor_end) {
186 ComputeFilterCoordinates<ALIGN_CORNERS, MAPPING>(
187 x, y, z, filter_size_xyz, inv_extents,
189 interpolation.Interpolate(
190 interp_weights, interp_indices, x, y, z,
191 filter_size_xyz, in_channels);
192 for (
int k = 0; k < vec_valid_count; ++k) {
193 for (
int j = 0; j < InterpolationVec_t::Size();
195 for (
int ic = 0; ic < in_channels; ++ic)
196 B(interp_indices(j, k) + ic, out_col) +=
197 TFeat(interp_weights(j, k)) *
207 Eigen::Map<
const Eigen::Matrix<TFeat, Eigen::Dynamic,
209 A(filter, out_channels,
210 spatial_filter_size * in_channels);
211 Eigen::Map<Eigen::Matrix<TOut, Eigen::Dynamic, Eigen::Dynamic>>
212 C(out_features + (r.begin() * out_channels),
213 out_channels, range_length);
215 C = (A * B).
template cast<TOut>();
216 if (out_importance) {
217 for (
int i = 0; i < range_length; ++i)
218 C.col(i) *= TOut(out_importance[r.begin() + i]);
304 template <
class TFeat,
class TOut,
class TReal,
class TIndex>
306 const std::vector<int>& filter_dims,
309 const TReal* out_positions,
310 const TFeat* out_importance,
312 const TReal* inp_positions,
313 const TFeat* inp_features,
314 const TFeat* inp_neighbors_importance_sum,
315 const int64_t* inp_neighbors_row_splits,
316 size_t neighbors_index_size,
317 const TIndex* neighbors_index,
318 const TFeat* neighbors_importance,
319 const int64_t* neighbors_row_splits,
320 const TReal* extents,
321 const TReal* offsets,
325 bool individual_extent,
326 bool isotropic_extent,
328 #define FN_PARAMETERS \ 329 out_features, filter_dims, filter, num_out, out_positions, out_importance, \ 330 num_inp, inp_positions, inp_features, \ 331 inp_neighbors_importance_sum, inp_neighbors_row_splits, \ 332 neighbors_index_size, neighbors_index, neighbors_importance, \ 333 neighbors_row_splits, extents, offsets 335 #define CALL_TEMPLATE(INTERPOLATION, MAPPING, ALIGN_CORNERS, \ 336 INDIVIDUAL_EXTENT, ISOTROPIC_EXTENT, NORMALIZE) \ 337 if (INTERPOLATION == interpolation && MAPPING == coordinate_mapping && \ 338 ALIGN_CORNERS == align_corners && \ 339 INDIVIDUAL_EXTENT == individual_extent && \ 340 ISOTROPIC_EXTENT == isotropic_extent && NORMALIZE == normalize) \ 341 _CConvTransposeComputeFeaturesCPU<TFeat, TOut, TReal, TIndex, \ 342 INTERPOLATION, MAPPING, \ 343 ALIGN_CORNERS, INDIVIDUAL_EXTENT, \ 344 ISOTROPIC_EXTENT, NORMALIZE>( \ 347 #define CALL_TEMPLATE2(INTERPOLATION, MAPPING) \ 348 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, true, true) \ 349 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, true, false) \ 350 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, false, true) \ 351 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, true, false, false) \ 352 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, true, true) \ 353 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, true, false) \ 354 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, false, true) \ 355 CALL_TEMPLATE(INTERPOLATION, MAPPING, true, false, false, false) \ 356 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, true, true) \ 357 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, true, false) \ 358 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, false, true) \ 359 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, true, false, false) \ 360 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, true, true) \ 361 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, true, false) \ 362 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, false, true) \ 363 CALL_TEMPLATE(INTERPOLATION, MAPPING, false, false, false, false) 365 #define CALL_TEMPLATE3(INTERPOLATION) \ 366 CALL_TEMPLATE2(INTERPOLATION, CoordinateMapping::BALL_TO_CUBE_RADIAL) \ 367 CALL_TEMPLATE2(INTERPOLATION, \ 368 CoordinateMapping::BALL_TO_CUBE_VOLUME_PRESERVING) \ 369 CALL_TEMPLATE2(INTERPOLATION, CoordinateMapping::IDENTITY) 371 #define CALL_TEMPLATE4 \ 372 CALL_TEMPLATE3(InterpolationMode::LINEAR) \ 373 CALL_TEMPLATE3(InterpolationMode::LINEAR_BORDER) \ 374 CALL_TEMPLATE3(InterpolationMode::NEAREST_NEIGHBOR) 379 #undef CALL_TEMPLATE2 380 #undef CALL_TEMPLATE3 381 #undef CALL_TEMPLATE4
InterpolationMode
Definition: ContinuousConvTypes.h:37
Class for computing interpolation weights.
Definition: CoordinateTransformation.h:204
CoordinateMapping
Definition: ContinuousConvTypes.h:45
Definition: PinholeCameraIntrinsic.cpp:35
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:305
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:49