|
|
|
@ -24,7 +24,7 @@ class Pool2dFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
void operator()(const platform::DeviceContext& context,
|
|
|
|
|
const framework::Tensor& input, framework::Tensor& output,
|
|
|
|
|
std::vector<int>& ksize, std::vector<int>& strides,
|
|
|
|
|
std::vector<int>& paddings, PoolProcess pool_compute) {
|
|
|
|
|
std::vector<int>& paddings, PoolProcess pool_process) {
|
|
|
|
|
const int batch_size = input.dims()[0];
|
|
|
|
|
const int input_height = input.dims()[2];
|
|
|
|
|
const int input_width = input.dims()[3];
|
|
|
|
@ -54,14 +54,15 @@ class Pool2dFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
int wstart = pw * stride_width - padding_width;
|
|
|
|
|
int wend = std::min(wstart + ksize_width, input_width);
|
|
|
|
|
wstart = std::max(wstart, 0);
|
|
|
|
|
T ele = pool_compute.initial();
|
|
|
|
|
|
|
|
|
|
T ele = pool_process.initial();
|
|
|
|
|
for (int h = hstart; h < hend; ++h) {
|
|
|
|
|
for (int w = wstart; w < wend; ++w) {
|
|
|
|
|
pool_compute.compute(ele, input_data[h * input_width + w]);
|
|
|
|
|
pool_process.compute(ele, input_data[h * input_width + w]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int pool_size = (hend - hstart) * (wend - wstart);
|
|
|
|
|
pool_compute.finalize(ele, (static_cast<T>(pool_size)));
|
|
|
|
|
pool_process.finalize(ele, (static_cast<T>(pool_size)));
|
|
|
|
|
output_data[ph * output_width + pw] = ele;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -80,7 +81,7 @@ class Pool2dGradFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
const framework::Tensor& output,
|
|
|
|
|
const framework::Tensor& output_grad, std::vector<int>& ksize,
|
|
|
|
|
std::vector<int>& strides, std::vector<int>& paddings,
|
|
|
|
|
PoolProcess pool_compute) {
|
|
|
|
|
PoolProcess pool_grad_process) {
|
|
|
|
|
const int batch_size = input.dims()[0];
|
|
|
|
|
const int input_height = input.dims()[2];
|
|
|
|
|
const int input_width = input.dims()[3];
|
|
|
|
@ -115,11 +116,12 @@ class Pool2dGradFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
float scale = 1.0 / pool_size;
|
|
|
|
|
for (int h = hstart; h < hend; ++h) {
|
|
|
|
|
for (int w = wstart; w < wend; ++w) {
|
|
|
|
|
pool_compute.compute(input_data[h * input_width + w],
|
|
|
|
|
output_data[ph * output_width + pw],
|
|
|
|
|
output_grad_data[ph * output_width + pw],
|
|
|
|
|
input_grad_data[h * input_width + w],
|
|
|
|
|
static_cast<T>(scale));
|
|
|
|
|
pool_grad_process.compute(
|
|
|
|
|
input_data[h * input_width + w],
|
|
|
|
|
output_data[ph * output_width + pw],
|
|
|
|
|
output_grad_data[ph * output_width + pw],
|
|
|
|
|
input_grad_data[h * input_width + w],
|
|
|
|
|
static_cast<T>(scale));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -198,21 +200,21 @@ template class MaxPool2dGradFunctor<platform::CPUPlace, float>;
|
|
|
|
|
// template class MaxPool2dGradFunctor<platform::CPUPlace, double>;
|
|
|
|
|
|
|
|
|
|
template class Pool2dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::maxPool<float>, float>;
|
|
|
|
|
paddle::operators::math::MaxPool<float>, float>;
|
|
|
|
|
template class Pool2dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::avgPool<float>, float>;
|
|
|
|
|
paddle::operators::math::AvgPool<float>, float>;
|
|
|
|
|
template class Pool2dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::maxPoolGrad<float>, float>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::MaxPoolGrad<float>, float>;
|
|
|
|
|
template class Pool2dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::avgPoolGrad<float>, float>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::AvgPoolGrad<float>, float>;
|
|
|
|
|
template class Pool2dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::maxPool<double>, double>;
|
|
|
|
|
paddle::operators::math::MaxPool<double>, double>;
|
|
|
|
|
template class Pool2dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::avgPool<double>, double>;
|
|
|
|
|
paddle::operators::math::AvgPool<double>, double>;
|
|
|
|
|
template class Pool2dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::maxPoolGrad<double>, double>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::MaxPoolGrad<double>, double>;
|
|
|
|
|
template class Pool2dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::avgPoolGrad<double>, double>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::AvgPoolGrad<double>, double>;
|
|
|
|
|
|
|
|
|
|
template <typename PoolProcess, class T>
|
|
|
|
|
class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
@ -220,7 +222,7 @@ class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
void operator()(const platform::DeviceContext& context,
|
|
|
|
|
const framework::Tensor& input, framework::Tensor& output,
|
|
|
|
|
std::vector<int>& ksize, std::vector<int>& strides,
|
|
|
|
|
std::vector<int>& paddings, PoolProcess pool_compute) {
|
|
|
|
|
std::vector<int>& paddings, PoolProcess pool_process) {
|
|
|
|
|
const int batch_size = input.dims()[0];
|
|
|
|
|
const int input_depth = input.dims()[2];
|
|
|
|
|
const int input_height = input.dims()[3];
|
|
|
|
@ -260,11 +262,11 @@ class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
int wend = std::min(wstart + ksize_width, input_width);
|
|
|
|
|
wstart = std::max(wstart, 0);
|
|
|
|
|
int output_idx = (pd * output_height + ph) * output_width + pw;
|
|
|
|
|
T ele = pool_compute.initial();
|
|
|
|
|
T ele = pool_process.initial();
|
|
|
|
|
for (int d = dstart; d < dend; ++d) {
|
|
|
|
|
for (int h = hstart; h < hend; ++h) {
|
|
|
|
|
for (int w = wstart; w < wend; ++w) {
|
|
|
|
|
pool_compute.compute(
|
|
|
|
|
pool_process.compute(
|
|
|
|
|
ele,
|
|
|
|
|
input_data[(d * input_height + h) * input_width + w]);
|
|
|
|
|
}
|
|
|
|
@ -272,7 +274,7 @@ class Pool3dFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
}
|
|
|
|
|
int pool_size =
|
|
|
|
|
(dend - dstart) * (hend - hstart) * (wend - wstart);
|
|
|
|
|
pool_compute.finalize(ele, static_cast<T>(pool_size));
|
|
|
|
|
pool_process.finalize(ele, static_cast<T>(pool_size));
|
|
|
|
|
output_data[output_idx] = ele;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -292,7 +294,7 @@ class Pool3dGradFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
const framework::Tensor& output,
|
|
|
|
|
const framework::Tensor& output_grad, std::vector<int>& ksize,
|
|
|
|
|
std::vector<int>& strides, std::vector<int>& paddings,
|
|
|
|
|
PoolProcess pool_compute) {
|
|
|
|
|
PoolProcess pool_grad_process) {
|
|
|
|
|
const int batch_size = input.dims()[0];
|
|
|
|
|
const int input_depth = input.dims()[2];
|
|
|
|
|
const int input_height = input.dims()[3];
|
|
|
|
@ -343,7 +345,7 @@ class Pool3dGradFunctor<platform::CPUPlace, PoolProcess, T> {
|
|
|
|
|
int input_idx = (d * input_height + h) * input_width + w;
|
|
|
|
|
int output_idx =
|
|
|
|
|
(pd * output_height + ph) * output_width + pw;
|
|
|
|
|
pool_compute.compute(
|
|
|
|
|
pool_grad_process.compute(
|
|
|
|
|
input_data[input_idx], output_data[output_idx],
|
|
|
|
|
output_grad_data[output_idx],
|
|
|
|
|
input_grad_data[input_idx], static_cast<T>(scale));
|
|
|
|
@ -441,21 +443,21 @@ template class MaxPool3dGradFunctor<platform::CPUPlace, float>;
|
|
|
|
|
// template class MaxPool3dGradFunctor<platform::CPUPlace, double>;
|
|
|
|
|
|
|
|
|
|
template class Pool3dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::maxPool<float>, float>;
|
|
|
|
|
paddle::operators::math::MaxPool<float>, float>;
|
|
|
|
|
template class Pool3dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::avgPool<float>, float>;
|
|
|
|
|
paddle::operators::math::AvgPool<float>, float>;
|
|
|
|
|
template class Pool3dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::maxPoolGrad<float>, float>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::MaxPoolGrad<float>, float>;
|
|
|
|
|
template class Pool3dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::avgPoolGrad<float>, float>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::AvgPoolGrad<float>, float>;
|
|
|
|
|
template class Pool3dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::maxPool<double>, double>;
|
|
|
|
|
paddle::operators::math::MaxPool<double>, double>;
|
|
|
|
|
template class Pool3dFunctor<platform::CPUPlace,
|
|
|
|
|
paddle::operators::math::avgPool<double>, double>;
|
|
|
|
|
paddle::operators::math::AvgPool<double>, double>;
|
|
|
|
|
template class Pool3dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::maxPoolGrad<double>, double>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::MaxPoolGrad<double>, double>;
|
|
|
|
|
template class Pool3dGradFunctor<
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::avgPoolGrad<double>, double>;
|
|
|
|
|
platform::CPUPlace, paddle::operators::math::AvgPoolGrad<double>, double>;
|
|
|
|
|
} // namespace math
|
|
|
|
|
} // namespace operators
|
|
|
|
|
} // namespace paddle
|
|
|
|
|