|
|
|
@ -29,14 +29,16 @@ void TestIm2ColFunctor() {
|
|
|
|
|
for (size_t filterWidth : {3, 7}) {
|
|
|
|
|
for (size_t stride : {1, 2}) {
|
|
|
|
|
for (size_t padding : {0, 1}) {
|
|
|
|
|
if (inputHeight <= filterHeight || inputWidth <= filterWidth)
|
|
|
|
|
for (size_t dilation : {1, 3}) {
|
|
|
|
|
size_t filterSizeH = (filterHeight - 1) * dilation + 1;
|
|
|
|
|
size_t filterSizeW = (filterWidth - 1) * dilation + 1;
|
|
|
|
|
if (inputHeight <= filterSizeH || inputWidth <= filterSizeW)
|
|
|
|
|
break;
|
|
|
|
|
if (padding >= filterHeight || padding >= filterWidth) break;
|
|
|
|
|
if (padding >= filterSizeH || padding >= filterSizeW) break;
|
|
|
|
|
size_t outputHeight =
|
|
|
|
|
(inputHeight - filterHeight + 2 * padding + stride) /
|
|
|
|
|
stride;
|
|
|
|
|
(inputHeight - filterSizeH + 2 * padding) / stride + 1;
|
|
|
|
|
size_t outputWidth =
|
|
|
|
|
(inputWidth - filterWidth + 2 * padding + stride) / stride;
|
|
|
|
|
(inputWidth - filterSizeW + 2 * padding) / stride + 1;
|
|
|
|
|
|
|
|
|
|
TensorShape imShape =
|
|
|
|
|
TensorShape({channels, inputHeight, inputWidth});
|
|
|
|
@ -53,10 +55,14 @@ void TestIm2ColFunctor() {
|
|
|
|
|
|
|
|
|
|
size_t height = channels * filterHeight * filterWidth;
|
|
|
|
|
size_t width = outputHeight * outputWidth;
|
|
|
|
|
VectorPtr input1 = Vector::create(imShape.getElements(), false);
|
|
|
|
|
VectorPtr input2 = Vector::create(imShape.getElements(), false);
|
|
|
|
|
MatrixPtr output1 = Matrix::create(height, width, false, false);
|
|
|
|
|
MatrixPtr output2 = Matrix::create(width, height, false, false);
|
|
|
|
|
VectorPtr input1 =
|
|
|
|
|
Vector::create(imShape.getElements(), false);
|
|
|
|
|
VectorPtr input2 =
|
|
|
|
|
Vector::create(imShape.getElements(), false);
|
|
|
|
|
MatrixPtr output1 =
|
|
|
|
|
Matrix::create(height, width, false, false);
|
|
|
|
|
MatrixPtr output2 =
|
|
|
|
|
Matrix::create(width, height, false, false);
|
|
|
|
|
input1->uniform(0.001, 1);
|
|
|
|
|
input2->copyFrom(*input1);
|
|
|
|
|
|
|
|
|
@ -69,7 +75,9 @@ void TestIm2ColFunctor() {
|
|
|
|
|
stride,
|
|
|
|
|
stride,
|
|
|
|
|
padding,
|
|
|
|
|
padding);
|
|
|
|
|
padding,
|
|
|
|
|
dilation,
|
|
|
|
|
dilation);
|
|
|
|
|
im2Col2(input2->getData(),
|
|
|
|
|
imShape,
|
|
|
|
|
output2->getData(),
|
|
|
|
@ -77,7 +85,9 @@ void TestIm2ColFunctor() {
|
|
|
|
|
stride,
|
|
|
|
|
stride,
|
|
|
|
|
padding,
|
|
|
|
|
padding);
|
|
|
|
|
padding,
|
|
|
|
|
dilation,
|
|
|
|
|
dilation);
|
|
|
|
|
|
|
|
|
|
// The transposition of the result of ColFormat == kCFO
|
|
|
|
|
// is equal to the result of ColFormat == kOCF.
|
|
|
|
@ -87,6 +97,7 @@ void TestIm2ColFunctor() {
|
|
|
|
|
|
|
|
|
|
Col2ImFunctor<kCFO, Device, T> col2Im1;
|
|
|
|
|
Col2ImFunctor<kOCF, Device, T> col2Im2;
|
|
|
|
|
|
|
|
|
|
col2Im1(input1->getData(),
|
|
|
|
|
imShape,
|
|
|
|
|
output1->getData(),
|
|
|
|
@ -94,7 +105,9 @@ void TestIm2ColFunctor() {
|
|
|
|
|
stride,
|
|
|
|
|
stride,
|
|
|
|
|
padding,
|
|
|
|
|
padding);
|
|
|
|
|
padding,
|
|
|
|
|
dilation,
|
|
|
|
|
dilation);
|
|
|
|
|
col2Im2(input2->getData(),
|
|
|
|
|
imShape,
|
|
|
|
|
output2->getData(),
|
|
|
|
@ -102,8 +115,9 @@ void TestIm2ColFunctor() {
|
|
|
|
|
stride,
|
|
|
|
|
stride,
|
|
|
|
|
padding,
|
|
|
|
|
padding);
|
|
|
|
|
|
|
|
|
|
padding,
|
|
|
|
|
dilation,
|
|
|
|
|
dilation);
|
|
|
|
|
autotest::TensorCheckErr(*input1, *input2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -112,6 +126,7 @@ void TestIm2ColFunctor() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Im2ColFunctor, CPU) { TestIm2ColFunctor<DEVICE_TYPE_CPU, float>(); }
|
|
|
|
|