fix doc errors. test=develop

for_weibo
dengkaipeng 6 years ago
parent cf06e50f1d
commit a81fabd327

@ -19,16 +19,6 @@ namespace paddle {
namespace operators {
namespace math {
static inline int ADAPT_START_INDEX(int ph, int input_size, int output_size) {
return static_cast<int>(
floor(static_cast<float>(ph * input_size) / output_size));
}
static inline int ADAPT_END_INDEX(int ph, int input_size, int output_size) {
return static_cast<int>(
ceil(static_cast<float>((ph + 1) * input_size) / output_size));
}
/*
* All tensors are in NCHW format.
* Ksize, strides, paddings are two elements. These two elements represent
@ -67,8 +57,8 @@ class Pool2dFunctor<platform::CPUDeviceContext, PoolProcess, T> {
for (int c = 0; c < output_channels; ++c) {
for (int ph = 0; ph < output_height; ++ph) {
if (adaptive) {
hstart = ADAPT_START_INDEX(ph, input_height, output_height);
hend = ADAPT_END_INDEX(ph, input_height, output_height);
hstart = AdaptStartIndex(ph, input_height, output_height);
hend = AdaptEndIndex(ph, input_height, output_height);
} else {
hstart = ph * stride_height - padding_height;
hend = std::min(hstart + ksize_height, input_height);
@ -76,8 +66,8 @@ class Pool2dFunctor<platform::CPUDeviceContext, PoolProcess, T> {
}
for (int pw = 0; pw < output_width; ++pw) {
if (adaptive) {
wstart = ADAPT_START_INDEX(pw, input_width, output_width);
wend = ADAPT_END_INDEX(pw, input_width, output_width);
wstart = AdaptStartIndex(pw, input_width, output_width);
wend = AdaptEndIndex(pw, input_width, output_width);
} else {
wstart = pw * stride_width - padding_width;
wend = std::min(wstart + ksize_width, input_width);
@ -144,8 +134,8 @@ class Pool2dGradFunctor<platform::CPUDeviceContext, PoolProcess, T> {
for (int c = 0; c < output_channels; ++c) {
for (int ph = 0; ph < output_height; ++ph) {
if (adaptive) {
hstart = ADAPT_START_INDEX(ph, input_height, output_height);
hend = ADAPT_END_INDEX(ph, input_height, output_height);
hstart = AdaptStartIndex(ph, input_height, output_height);
hend = AdaptEndIndex(ph, input_height, output_height);
} else {
hstart = ph * stride_height - padding_height;
hend = std::min(hstart + ksize_height, input_height);
@ -153,8 +143,8 @@ class Pool2dGradFunctor<platform::CPUDeviceContext, PoolProcess, T> {
}
for (int pw = 0; pw < output_width; ++pw) {
if (adaptive) {
wstart = ADAPT_START_INDEX(pw, input_width, output_width);
wend = ADAPT_END_INDEX(pw, input_width, output_width);
wstart = AdaptStartIndex(pw, input_width, output_width);
wend = AdaptEndIndex(pw, input_width, output_width);
} else {
wstart = pw * stride_width - padding_width;
wend = std::min(wstart + ksize_width, input_width);
@ -319,8 +309,8 @@ class Pool3dFunctor<platform::CPUDeviceContext, PoolProcess, T> {
for (int c = 0; c < output_channels; ++c) {
for (int pd = 0; pd < output_depth; ++pd) {
if (adaptive) {
dstart = ADAPT_START_INDEX(pd, input_depth, output_depth);
dend = ADAPT_END_INDEX(pd, input_depth, output_depth);
dstart = AdaptStartIndex(pd, input_depth, output_depth);
dend = AdaptEndIndex(pd, input_depth, output_depth);
} else {
dstart = pd * stride_depth - padding_depth;
dend = std::min(dstart + ksize_depth, input_depth);
@ -328,8 +318,8 @@ class Pool3dFunctor<platform::CPUDeviceContext, PoolProcess, T> {
}
for (int ph = 0; ph < output_height; ++ph) {
if (adaptive) {
hstart = ADAPT_START_INDEX(ph, input_height, output_height);
hend = ADAPT_END_INDEX(ph, input_height, output_height);
hstart = AdaptStartIndex(ph, input_height, output_height);
hend = AdaptEndIndex(ph, input_height, output_height);
} else {
hstart = ph * stride_height - padding_height;
hend = std::min(hstart + ksize_height, input_height);
@ -337,8 +327,8 @@ class Pool3dFunctor<platform::CPUDeviceContext, PoolProcess, T> {
}
for (int pw = 0; pw < output_width; ++pw) {
if (adaptive) {
wstart = ADAPT_START_INDEX(pw, input_width, output_width);
wend = ADAPT_END_INDEX(pw, input_width, output_width);
wstart = AdaptStartIndex(pw, input_width, output_width);
wend = AdaptEndIndex(pw, input_width, output_width);
} else {
wstart = pw * stride_width - padding_width;
wend = std::min(wstart + ksize_width, input_width);
@ -417,8 +407,8 @@ class Pool3dGradFunctor<platform::CPUDeviceContext, PoolProcess, T> {
for (int c = 0; c < output_channels; ++c) {
for (int pd = 0; pd < output_depth; ++pd) {
if (adaptive) {
dstart = ADAPT_START_INDEX(pd, input_depth, output_depth);
dend = ADAPT_END_INDEX(pd, input_depth, output_depth);
dstart = AdaptStartIndex(pd, input_depth, output_depth);
dend = AdaptEndIndex(pd, input_depth, output_depth);
} else {
dstart = pd * stride_depth - padding_depth;
dend = std::min(dstart + ksize_depth, input_depth);
@ -426,8 +416,8 @@ class Pool3dGradFunctor<platform::CPUDeviceContext, PoolProcess, T> {
}
for (int ph = 0; ph < output_height; ++ph) {
if (adaptive) {
hstart = ADAPT_START_INDEX(ph, input_height, output_height);
hend = ADAPT_END_INDEX(ph, input_height, output_height);
hstart = AdaptStartIndex(ph, input_height, output_height);
hend = AdaptEndIndex(ph, input_height, output_height);
} else {
hstart = ph * stride_height - padding_height;
hend = std::min(hstart + ksize_height, input_height);
@ -435,8 +425,8 @@ class Pool3dGradFunctor<platform::CPUDeviceContext, PoolProcess, T> {
}
for (int pw = 0; pw < output_width; ++pw) {
if (adaptive) {
wstart = ADAPT_START_INDEX(pw, input_width, output_width);
wend = ADAPT_END_INDEX(pw, input_width, output_width);
wstart = AdaptStartIndex(pw, input_width, output_width);
wend = AdaptEndIndex(pw, input_width, output_width);
} else {
wstart = pw * stride_width - padding_width;
wend = std::min(wstart + ksize_width, input_width);
@ -615,8 +605,8 @@ class MaxPool2dWithIndexFunctor<platform::CPUDeviceContext, T1, T2> {
for (int c = 0; c < output_channels; ++c) {
for (int ph = 0; ph < output_height; ++ph) {
if (adaptive) {
hstart = ADAPT_START_INDEX(ph, input_height, output_height);
hend = ADAPT_END_INDEX(ph, input_height, output_height);
hstart = AdaptStartIndex(ph, input_height, output_height);
hend = AdaptEndIndex(ph, input_height, output_height);
} else {
hstart = ph * stride_height - padding_height;
hend = std::min(hstart + ksize_height, input_height);
@ -624,8 +614,8 @@ class MaxPool2dWithIndexFunctor<platform::CPUDeviceContext, T1, T2> {
}
for (int pw = 0; pw < output_width; ++pw) {
if (adaptive) {
wstart = ADAPT_START_INDEX(pw, input_width, output_width);
wend = ADAPT_END_INDEX(pw, input_width, output_width);
wstart = AdaptStartIndex(pw, input_width, output_width);
wend = AdaptEndIndex(pw, input_width, output_width);
} else {
wstart = pw * stride_width - padding_width;
wend = std::min(wstart + ksize_width, input_width);
@ -753,8 +743,8 @@ class MaxPool3dWithIndexFunctor<platform::CPUDeviceContext, T1, T2> {
for (int c = 0; c < output_channels; ++c) {
for (int pd = 0; pd < output_depth; ++pd) {
if (adaptive) {
dstart = ADAPT_START_INDEX(pd, input_depth, output_depth);
dend = ADAPT_END_INDEX(pd, input_depth, output_depth);
dstart = AdaptStartIndex(pd, input_depth, output_depth);
dend = AdaptEndIndex(pd, input_depth, output_depth);
} else {
dstart = pd * stride_depth - padding_depth;
dend = std::min(dstart + ksize_depth, input_depth);
@ -762,8 +752,8 @@ class MaxPool3dWithIndexFunctor<platform::CPUDeviceContext, T1, T2> {
}
for (int ph = 0; ph < output_height; ++ph) {
if (adaptive) {
hstart = ADAPT_START_INDEX(ph, input_height, output_height);
hend = ADAPT_END_INDEX(ph, input_height, output_height);
hstart = AdaptStartIndex(ph, input_height, output_height);
hend = AdaptEndIndex(ph, input_height, output_height);
} else {
hstart = ph * stride_height - padding_height;
hend = std::min(hstart + ksize_height, input_height);
@ -771,8 +761,8 @@ class MaxPool3dWithIndexFunctor<platform::CPUDeviceContext, T1, T2> {
}
for (int pw = 0; pw < output_width; ++pw) {
if (adaptive) {
wstart = ADAPT_START_INDEX(pw, input_width, output_width);
wend = ADAPT_END_INDEX(pw, input_width, output_width);
wstart = AdaptStartIndex(pw, input_width, output_width);
wend = AdaptEndIndex(pw, input_width, output_width);
} else {
wstart = pw * stride_width - padding_width;
wend = std::min(wstart + ksize_width, input_width);

File diff suppressed because it is too large Load Diff

@ -68,6 +68,18 @@ class AvgPoolGrad {
}
};
/* used for adaptive pool to calculate start and end index of each divided grid
*/
HOSTDEVICE inline int AdaptStartIndex(int ph, int input_size, int output_size) {
return static_cast<int>(
floor(static_cast<double>(ph * input_size) / output_size));
}
HOSTDEVICE inline int AdaptEndIndex(int ph, int input_size, int output_size) {
return static_cast<int>(
ceil(static_cast<double>((ph + 1) * input_size) / output_size));
}
/*
* \brief Getting pooling results, and calculating gradient.
*

@ -2506,7 +2506,7 @@ def adaptive_pool2d(input,
pool_size,
pool_type="max",
require_index=False,
use_cudnn=True,
use_cudnn=False,
name=None):
"""
${comment}
@ -2521,7 +2521,7 @@ def adaptive_pool2d(input,
pool_type: ${pooling_type_comment}
require_index (bool): If true, the index of max pooling point along with outputs.
it cannot be set in average pooling type.
use_cudnn (bool): ${use_cudnn_comment}
use_cudnn (bool, default False): adaptive pool currently not supported in cudnn.
name (str|None): A name for this layer(optional). If set None, the
layer will be named automatically.
@ -2531,6 +2531,7 @@ def adaptive_pool2d(input,
Raises:
ValueError: 'pool_type' is not 'max' nor 'avg'.
ValueError: 'use_cudnn' is not a bool value.
ValueError: adaptive pool currently not supported in cudnn.
ValueError: invalid setting 'require_index' true when 'pool_type' is 'avg'.
ValueError: 'pool_size' should be a list or tuple with length as 2.
@ -2540,11 +2541,11 @@ def adaptive_pool2d(input,
data = fluid.layers.data(
name='data', shape=[3, 32, 32], dtype='float32')
conv2d = fluid.layers.pool2d(
pool_out = fluid.layers.adaptive_pool2d(
input=data,
pool_size=[3, 3],
pool_type='max',
require_index=True)
require_index=False)
"""
if pool_type not in ["max", "avg"]:
raise ValueError(
@ -2565,6 +2566,9 @@ def adaptive_pool2d(input,
if not isinstance(use_cudnn, bool):
raise ValueError("use_cudnn should be True or False.")
if use_cudnn:
raise ValueError("adaptive pool currently not supported in cudnn.")
if pool_type == "max":
l_type = 'max_pool2d_with_index'
else:
@ -2590,7 +2594,7 @@ def adaptive_pool2d(input,
"adaptive": True,
})
return pool_out
return (pool_out, mask) if require_index else pool_out
@templatedoc(op_type="pool3d")
@ -2598,7 +2602,7 @@ def adaptive_pool3d(input,
pool_size,
pool_type="max",
require_index=False,
use_cudnn=True,
use_cudnn=False,
name=None):
"""
${comment}
@ -2613,7 +2617,7 @@ def adaptive_pool3d(input,
pool_type: ${pooling_type_comment}
require_index (bool): If true, the index of max pooling point along with outputs.
it cannot be set in average pooling type.
use_cudnn (bool): ${use_cudnn_comment}
use_cudnn (bool, default False): adaptive pool currently not supported in cudnn.
name (str|None): A name for this layer(optional). If set None, the
layer will be named automatically.
@ -2623,6 +2627,7 @@ def adaptive_pool3d(input,
Raises:
ValueError: 'pool_type' is not 'max' nor 'avg'.
ValueError: 'use_cudnn' is not a bool value.
ValueError: adaptive pool currently not supported in cudnn.
ValueError: invalid setting 'require_index' true when 'pool_type' is 'avg'.
ValueError: 'pool_size' should be a list or tuple with length as 2.
@ -2632,7 +2637,7 @@ def adaptive_pool3d(input,
data = fluid.layers.data(
name='data', shape=[3, 32, 32], dtype='float32')
conv2d = fluid.layers.pool2d(
pool_out, mask = fluid.layers.adaptive_pool3d(
input=data,
pool_size=[3, 3],
pool_type='max',
@ -2657,6 +2662,9 @@ def adaptive_pool3d(input,
if not isinstance(use_cudnn, bool):
raise ValueError("use_cudnn should be True or False.")
if use_cudnn:
raise ValueError("adaptive pool currently not supported in cudnn.")
if pool_type == "max":
l_type = 'max_pool3d_with_index'
else:
@ -2682,7 +2690,7 @@ def adaptive_pool3d(input,
"adaptive": True,
})
return pool_out
return (pool_out, mask) if require_index else pool_out
def batch_norm(input,

@ -237,23 +237,24 @@ class TestBook(unittest.TestCase):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[3, 224, 224], dtype='float32')
self.assertIsNotNone(
layers.adaptive_pool2d(
x, [3, 3], require_index=True))
self.assertIsNotNone(
layers.adaptive_pool2d(
x, [3, 3], pool_type='avg'))
pool, mask = layers.adaptive_pool2d(x, [3, 3], require_index=True)
self.assertIsNotNone(pool)
self.assertIsNotNone(mask)
def test_adaptive_pool3d(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[3, 244, 224, 224], dtype='float32')
self.assertIsNotNone(
layers.adaptive_pool3d(
x, [3, 3, 3], require_index=True))
self.assertIsNotNone(
layers.adaptive_pool3d(
x, [3, 3, 3], pool_type='avg'))
pool, mask = layers.adaptive_pool3d(
x, [3, 3, 3], require_index=True)
self.assertIsNotNone(pool)
self.assertIsNotNone(mask)
def test_lstm_unit(self):
program = Program()

Loading…
Cancel
Save