|
|
@ -35,6 +35,12 @@ void testIm2col() {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* output_ocf = [0, 1, 3, 4
|
|
|
|
* output_ocf = [0, 1, 3, 4
|
|
|
|
* 1, 2, 4, 5]
|
|
|
|
* 1, 2, 4, 5]
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* col2im_cfo = [0, 2, 2
|
|
|
|
|
|
|
|
* 3, 4, 5]
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* col2im_ocf = [0, 2, 2
|
|
|
|
|
|
|
|
* 3, 4, 5]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int input_height = 2;
|
|
|
|
int input_height = 2;
|
|
|
|
int input_width = 3;
|
|
|
|
int input_width = 3;
|
|
|
@ -59,7 +65,7 @@ void testIm2col() {
|
|
|
|
new paddle::platform::CUDADeviceContext(paddle::platform::GPUPlace());
|
|
|
|
new paddle::platform::CUDADeviceContext(paddle::platform::GPUPlace());
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("no GPU support");
|
|
|
|
PADDLE_THROW("no GPU support");
|
|
|
|
#endif // PADDLE_ONLY_CPU
|
|
|
|
#endif // PADDLE_WITH_CUDA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
input = input_tmp;
|
|
|
|
input = input_tmp;
|
|
|
@ -71,6 +77,7 @@ void testIm2col() {
|
|
|
|
output_ocf.mutable_data<float>(
|
|
|
|
output_ocf.mutable_data<float>(
|
|
|
|
{output_height, output_width, 1, filter_size, filter_size}, *place);
|
|
|
|
{output_height, output_width, 1, filter_size, filter_size}, *place);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Im2Col
|
|
|
|
paddle::operators::math::Im2ColFunctor<
|
|
|
|
paddle::operators::math::Im2ColFunctor<
|
|
|
|
paddle::operators::math::ColFormat::kCFO, Place, float>
|
|
|
|
paddle::operators::math::ColFormat::kCFO, Place, float>
|
|
|
|
im2col;
|
|
|
|
im2col;
|
|
|
@ -79,8 +86,12 @@ void testIm2col() {
|
|
|
|
im2col_ocf;
|
|
|
|
im2col_ocf;
|
|
|
|
|
|
|
|
|
|
|
|
im2col(*context, input, output_cfo, stride, stride, padding, padding);
|
|
|
|
im2col(*context, input, output_cfo, stride, stride, padding, padding);
|
|
|
|
im2col_ocf(*context, input, output_ocf, stride, padding, 0,
|
|
|
|
im2col_ocf(*context, input, output_ocf, /*stride_height*/ stride,
|
|
|
|
output_height * output_width);
|
|
|
|
/*stride_width*/ stride, /*up_pad*/ padding,
|
|
|
|
|
|
|
|
/*down_pad*/ padding);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float out_cfo_data[] = {0, 1, 1, 2, 3, 4, 4, 5};
|
|
|
|
|
|
|
|
float out_ocf_data[] = {0, 1, 3, 4, 1, 2, 4, 5};
|
|
|
|
|
|
|
|
|
|
|
|
float* out_cfo_ptr;
|
|
|
|
float* out_cfo_ptr;
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
@ -90,14 +101,9 @@ void testIm2col() {
|
|
|
|
*context);
|
|
|
|
*context);
|
|
|
|
out_cfo_ptr = output_tmp.data<float>();
|
|
|
|
out_cfo_ptr = output_tmp.data<float>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_EQ(out_cfo_ptr[0], 0);
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
EXPECT_EQ(out_cfo_ptr[1], 1);
|
|
|
|
EXPECT_EQ(out_cfo_ptr[i], out_cfo_data[i]);
|
|
|
|
EXPECT_EQ(out_cfo_ptr[2], 1);
|
|
|
|
}
|
|
|
|
EXPECT_EQ(out_cfo_ptr[3], 2);
|
|
|
|
|
|
|
|
EXPECT_EQ(out_cfo_ptr[4], 3);
|
|
|
|
|
|
|
|
EXPECT_EQ(out_cfo_ptr[5], 4);
|
|
|
|
|
|
|
|
EXPECT_EQ(out_cfo_ptr[6], 4);
|
|
|
|
|
|
|
|
EXPECT_EQ(out_cfo_ptr[7], 5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float* out_ocf_ptr;
|
|
|
|
float* out_ocf_ptr;
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
@ -107,14 +113,60 @@ void testIm2col() {
|
|
|
|
*context);
|
|
|
|
*context);
|
|
|
|
out_ocf_ptr = output_tmp.data<float>();
|
|
|
|
out_ocf_ptr = output_tmp.data<float>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPECT_EQ(out_ocf_ptr[0], 0);
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
EXPECT_EQ(out_ocf_ptr[1], 1);
|
|
|
|
EXPECT_EQ(out_ocf_ptr[i], out_ocf_data[i]);
|
|
|
|
EXPECT_EQ(out_ocf_ptr[2], 3);
|
|
|
|
}
|
|
|
|
EXPECT_EQ(out_ocf_ptr[3], 4);
|
|
|
|
|
|
|
|
EXPECT_EQ(out_ocf_ptr[4], 1);
|
|
|
|
// Col2Im: kCFO
|
|
|
|
EXPECT_EQ(out_ocf_ptr[5], 2);
|
|
|
|
paddle::operators::math::Col2ImFunctor<
|
|
|
|
EXPECT_EQ(out_ocf_ptr[6], 4);
|
|
|
|
paddle::operators::math::ColFormat::kCFO, Place, float>
|
|
|
|
EXPECT_EQ(out_ocf_ptr[7], 5);
|
|
|
|
col2im;
|
|
|
|
|
|
|
|
paddle::operators::math::Col2ImFunctor<
|
|
|
|
|
|
|
|
paddle::operators::math::ColFormat::kOCF, Place, float>
|
|
|
|
|
|
|
|
col2im_ocf;
|
|
|
|
|
|
|
|
float col2im_data[] = {0, 2, 2, 3, 8, 5};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memset(input_ptr, 0, 6 * sizeof(float));
|
|
|
|
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
|
|
|
|
input = input_tmp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
input.CopyFrom<float>(input_tmp, *place, *context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
col2im(*context, input, output_cfo, stride, stride, padding, padding);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float* in_ptr;
|
|
|
|
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
|
|
|
|
in_ptr = input.data<float>();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
input_tmp.CopyFrom<float>(input, paddle::platform::CPUPlace(), *context);
|
|
|
|
|
|
|
|
in_ptr = input_tmp.data<float>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
|
|
|
|
EXPECT_EQ(in_ptr[i], col2im_data[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Col2Im: kOCF
|
|
|
|
|
|
|
|
memset(input_ptr, 0, 6 * sizeof(float));
|
|
|
|
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
|
|
|
|
input = input_tmp;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
input.CopyFrom<float>(input_tmp, *place, *context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
col2im_ocf(*context, input, output_ocf, /*stride_height*/ stride,
|
|
|
|
|
|
|
|
/*stride_width*/ stride, /*up_pad*/ padding,
|
|
|
|
|
|
|
|
/*down_pad*/ padding);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (paddle::platform::is_cpu_place(*place)) {
|
|
|
|
|
|
|
|
in_ptr = input.data<float>();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
input_tmp.CopyFrom<float>(input, paddle::platform::CPUPlace(), *context);
|
|
|
|
|
|
|
|
in_ptr = input_tmp.data<float>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
|
|
|
|
EXPECT_EQ(in_ptr[i], col2im_data[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(math, im2col) {
|
|
|
|
TEST(math, im2col) {
|
|
|
|