Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
211f83f
set depthwise conv layer interface in python
NHZlX Jul 4, 2017
eeb17c2
add depthwise operation and depthwise conv layer
NHZlX Jul 4, 2017
efae51c
add the mobilenet gpu acceleration, cpu is in the process
NHZlX Jul 7, 2017
f4e7ae5
add mobilenet gpu grad test, the test is ok
NHZlX Jul 7, 2017
36e7800
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 7, 2017
064dc88
add the comments for .h file and code tiny modify
NHZlX Jul 10, 2017
198164a
use the expandconvlayer forward and backward, add the explain for class
NHZlX Jul 10, 2017
a3ce6aa
add depthwise conv test
NHZlX Jul 10, 2017
e92f002
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 10, 2017
fd4b113
move DepthwiseConvOpTest.cpp to ConvOpTest.cpp
NHZlX Jul 12, 2017
433935a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 12, 2017
2bc08f8
modify format accored with clang-format 3.8
NHZlX Jul 12, 2017
ccd46d1
modify format accored with clang-format 3.8
NHZlX Jul 12, 2017
030a3db
the groups default should be None
NHZlX Jul 12, 2017
fc8aedb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 12, 2017
c43f693
modify the format and delete useless comment
NHZlX Jul 14, 2017
6267312
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 14, 2017
02e04b4
fuse the conv and depthwise conv together
NHZlX Jul 18, 2017
11588b3
support inputchannels != outputchannels of depthwiseconv
NHZlX Jul 18, 2017
d43fbba
add comments for python api
NHZlX Jul 18, 2017
44927bf
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 18, 2017
dbb6588
modity the format
NHZlX Jul 18, 2017
66520af
accelerate inputbackward(delete 'if' in this func) of depthwise conv
NHZlX Jul 19, 2017
d50c71f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 19, 2017
f7390d1
delete useless .h header in DepthwiseConvOpGpu.cu
NHZlX Jul 19, 2017
21ab0eb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 19, 2017
77ff97a
fuse interface of depthwise to expand in python api
NHZlX Jul 19, 2017
8199886
fuse interface of depthwise to expandconv
NHZlX Jul 19, 2017
1f516fa
modify format, and modify the layer grad test, op test
NHZlX Jul 19, 2017
bd54eb9
tiny modify the test
NHZlX Jul 19, 2017
4d6be97
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 20, 2017
5b07d4e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 20, 2017
248149f
add depthwiseconv test and fix the little bug of the convOpTest
NHZlX Jul 20, 2017
d5b0c57
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 20, 2017
cfd4c05
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
NHZlX Jul 21, 2017
e8d171b
add check for groups and inputChannels
NHZlX Jul 21, 2017
6c528cb
add check: CHECK_EQ(outputs[0].getArgType(), ADD_TO)
NHZlX Jul 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions paddle/function/ConvOpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,156 @@ class ConvolutionTest2 {
}
};

template <DeviceType DType1, DeviceType DType2>
class DepthwiseConvolutionTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我主要的意思是,看一下DepthwiseConvolutionTest 是否可以用ConvolutionTest替换,这两个大部分代码都是一样的。

public:
DepthwiseConvolutionTest(const std::string& conv1,
const std::string& conv2,
TestType type,
std::string algo = "auto") {
for (size_t batchSize : {1, 32}) {
for (size_t inputSize : {7, 14, 54}) {
for (size_t filterSize : {1, 3, 5}) {
for (size_t inputChannels : {64, 128}) {
size_t outputChannels = inputChannels;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputChannels != inputChannels的情况呢?

for (size_t stride : {1, 2}) {
for (size_t padding : {0, 1}) {
if (padding >= filterSize) break;
size_t outputSize =
(inputSize - filterSize + 2 * padding + stride) / stride;
VLOG(3) << " batchSize=" << batchSize
<< " inputChannels=" << inputChannels
<< " inputHeight=" << inputSize
<< " inputWidth=" << inputSize
<< " outputChannels=" << outputChannels
<< " filterHeight=" << filterSize
<< " filterWidth=" << filterSize
<< " outputHeight=" << outputSize
<< " outputWidth=" << outputSize << " stride=" << stride
<< " padding=" << padding;

std::vector<size_t> paddings = {padding, padding};
std::vector<size_t> strides = {stride, stride};
size_t groups = inputChannels;
Compare2Function<DType1, DType2> test(
conv1,
conv2,
FuncConfig()
.set("paddings", paddings)
.set("strides", strides)
.set("groups", groups)
.set("algo", algo));

TensorShape input{
batchSize, inputChannels, inputSize, inputSize};
TensorShape filter{inputChannels, 1, 1, filterSize, filterSize};
TensorShape output{
batchSize, outputChannels, outputSize, outputSize};

if (type == kForwardTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.run();
} else if (type == kBackwardInputTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, input), ADD_TO);
test.run();
} else if (type == kBackwardFilterTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.run();
}
}
}
}
}
}
}
}
};

// Mainly used to test cases where the height and width (input, filter)
// are not equal.
template <DeviceType DType1, DeviceType DType2>
class DepthwiseConvolutionTest2 {
public:
DepthwiseConvolutionTest2(const std::string& conv1,
const std::string& conv2,
TestType type,
std::string algo = "auto") {
for (size_t batchSize : {16}) {
for (size_t inputHeight : {7, 31}) {
for (size_t inputWidth : {10, 54}) {
for (size_t filterHeight : {1, 5}) {
for (size_t filterWidth : {3, 7}) {
for (size_t inputChannels : {32}) {
size_t outputChannels = inputChannels;
size_t stride = 1;
size_t padding = 0;
size_t outputHeight =
(inputHeight - filterHeight + 2 * padding + stride) /
stride;
size_t outputWidth =
(inputWidth - filterWidth + 2 * padding + stride) / stride;
VLOG(3) << " batchSize=" << batchSize
<< " inputChannels=" << inputChannels
<< " inputHeight=" << inputHeight
<< " inputWidth=" << inputWidth
<< " outputChannels=" << outputChannels
<< " filterHeight=" << filterHeight
<< " filterWidth=" << filterWidth
<< " outputHeight=" << outputHeight
<< " outputWidth=" << outputWidth
<< " stride=" << stride << " padding=" << padding;

std::vector<size_t> paddings = {padding, padding};
std::vector<size_t> strides = {stride, stride};
size_t groups = inputChannels;
Compare2Function<DType1, DType2> test(
conv1,
conv2,
FuncConfig()
.set("paddings", paddings)
.set("strides", strides)
.set("groups", groups)
.set("algo", algo));

TensorShape input{
batchSize, inputChannels, inputHeight, inputWidth};
TensorShape filter{
inputChannels, 1, 1, filterHeight, filterWidth};
TensorShape output{
batchSize, outputChannels, outputHeight, outputWidth};

if (type == kForwardTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.run();
} else if (type == kBackwardInputTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, input), ADD_TO);
test.run();
} else if (type == kBackwardFilterTest) {
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, output));
test.addInputs(BufferArg(VALUE_TYPE_FLOAT, input));
test.addOutputs(BufferArg(VALUE_TYPE_FLOAT, filter));
test.run();
}
}
}
}
}
}
}
}
};

// ======Start Convolution TEST======
TEST(Forward, GEMM) {
ConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_CPU> test(
"NaiveConv-CPU", "GemmConv-CPU", kForwardTest);
Expand Down Expand Up @@ -206,5 +356,49 @@ TEST(BackwardFilter, GEMM) {
"GemmConvGradFilter-CPU", "GemmConvGradFilter-GPU", kBackwardFilterTest);
}
#endif
// ======End Convolution TEST======

// ======Start DepthwiseConvolution TEST======
// TODO(zhaolong) The depthwise convolution cpu test will be added when the cpu
// version of depthwiseConv is implemented.

#ifndef PADDLE_ONLY_CPU
TEST(DepthwiseConvForward, GEMM) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些留个TEST接口就行了,实现先删了吧,没有什么意义,只是消耗测试时间。

DepthwiseConvolutionTest<DEVICE_TYPE_GPU, DEVICE_TYPE_GPU> test(
"GemmConv-GPU", "DepthwiseConv-GPU", kForwardTest);
DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"GemmConv-GPU", "DepthwiseConv-GPU", kForwardTest);
}

TEST(DepthwiseConvForward, GEMM2) {
DepthwiseConvolutionTest<DEVICE_TYPE_GPU, DEVICE_TYPE_GPU> test(
"DepthwiseConv-GPU", "DepthwiseConv-GPU", kForwardTest);
DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"DepthwiseConv-GPU", "DepthwiseConv-GPU", kForwardTest);
}

TEST(DepthwiseConvBackwardInput, GEMM) {
DepthwiseConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"DepthwiseConvGradInput-GPU",
"DepthwiseConvGradInput-GPU",
kBackwardInputTest);
DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"DepthwiseConvGradInput-GPU",
"DepthwiseConvGradInput-GPU",
kBackwardInputTest);
}

TEST(DepthwiseConvBackwardFilter, GEMM) {
DepthwiseConvolutionTest<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test(
"DepthwiseConvGradFilter-GPU",
"DepthwiseConvGradFilter-GPU",
kBackwardFilterTest);
DepthwiseConvolutionTest2<DEVICE_TYPE_CPU, DEVICE_TYPE_GPU> test2(
"DepthwiseConvGradFilter-GPU",
"DepthwiseConvGradFilter-GPU",
kBackwardFilterTest);
}
#endif
// ======End DepthwiseConvolution TEST======

} // namespace paddle
Loading