Add 3D Convolution operator implemented by GEMM.#4709
Add 3D Convolution operator implemented by GEMM.#4709chengduoZH merged 19 commits intoPaddlePaddle:developfrom
Conversation
|
conv
In convolution operations, |
18f8136 to
c51adfa
Compare
c51adfa to
96b4035
Compare
typhoonzero
left a comment
There was a problem hiding this comment.
In convolution operations, Conv2DOpGrad and Conv3DOpGrad are completely the same. Conv2DOp and Conv3DOp, Conv2DOpMaker and CudnnConv2DOpMaker, Conv3DOpMaker and CudnnConv3DOpMaker are respectively similar.
I think it is necessary to write a base class or write in one class, respectively.
This problem is also encountered in pooling operations and deconv.
So are you going to add a base class in this PR or next one?
Need to pull/rebase from develop branch.
paddle/operators/conv3d_op.cc
Outdated
| @@ -0,0 +1,117 @@ | |||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | |||
|
|
|||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||
There was a problem hiding this comment.
这里缩进下,保持和第一行一致。和其他的文件保持一致。
paddle/operators/conv3d_op.cc
Outdated
| Conv3DOpMaker::Conv3DOpMaker(framework::OpProto* proto, | ||
| framework::OpAttrChecker* op_checker) | ||
| : OpProtoAndCheckerMaker(proto, op_checker) { | ||
| AddInput( |
There was a problem hiding this comment.
这部分的确和2d很类似,可以用一个base class做一些代码复用。
| @@ -0,0 +1,22 @@ | |||
| /* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve. | |||
|
|
|||
| Licensed under the Apache License, Version 2.0 (the "License"); | |||
|
|
||
| output_group_channels = output_channels / self.groups | ||
| input_group_channels = input_channels / self.groups | ||
| for batchid in xrange(batch_size): |
There was a problem hiding this comment.
c++和python代码都实现一次计算感��比较冗余,python的unitest相当于认定python的conv实现一定是对的,然后来检测c++实现,但我们不一定都能保证python的实现都是对的(比如unitest部分某次commit更新错了,c++也有同样的错误,这样unitest虽然过了但不能保证计算是对的)。
我理解unitest中,需要有使用其他权威计算程序,比如matlab计算一组结果作为验证数据(包含边界条件的数据),同时验证python实现和c++实现,或者只验证c++实现
There was a problem hiding this comment.
python的unitest相当于认定python的conv实现一定是对的,然后来检测c++实现,但我们不一定都能保证python的实现都是对的
有道理。我觉得当前应该把python代码的写更直观易懂一些,如果某些包(如 numpy)中已经存在这些操作,最好直接调用。
There was a problem hiding this comment.
convolution在sci里的实现貌似只有1d的。放一个matlab算出来的结果作为test case会保险点。个人感觉,比如实现了一个add function,unitest必然是test下1+1=2
There was a problem hiding this comment.
c++和python代码都实现一次计算感觉比较冗余,python的unitest相当于认定python的conv实现一定是对的,然后来检测c++实现,但我们不一定都能保证python的实现都是对的(比如unitest部分某次commit更新错了,c++也有同样的错误,这样unitest虽然过了但不能保证计算是对的)。
恰巧看到这个comment。我也遇到类似的问题。CRF 的计算逻辑比较特殊化,单测我先用比较粗暴的策略写了一下。写的时候体会到,效果就是:python 写一遍,C++ 写一遍。到底哪个是对的呢?很可能都是错的。因为会直接照着python的逻辑抄到c++,或者反过来。
后面会再仔细想办法换策略来单测。python 写一遍,c++ 写一遍实在不是个好办法。
There was a problem hiding this comment.
卷积跟CRF可能还不完全一样,卷积这个例子,Python中用的是direct方式实现的,C++中一般用的是gemm或其他算法实现的;所以,相当于用一种算法实现检查另一种算法实现,单元测试这么写并没有什么问题。
There was a problem hiding this comment.
嗯,卷积这样比较常规的运算情况会好一些。CRF 有些特殊。
后面会再仔细想办法换策略来单测。python 写一遍,c++ 写一遍实在不是个好办法。
这个是说我自己这样测CRF的前向,不是个明智的做法。
There was a problem hiding this comment.
可不可以用老paddle的输出做一下对比?不过这样的前提是老paddle的输出得是正确的。
588b1b1 to
8c7edb5
Compare
c85db7e to
4a556b3
Compare
4a556b3 to
557c7ae
Compare
… Add_conv3d_gemm_op
|
|
||
| class TestCase1(TestConv3dOp): | ||
| def init_test_case(self): | ||
| # self.groups = 1 |
There was a problem hiding this comment.
Remove these commented lines.
| no_grad_set=set(['Input'])) | ||
|
|
||
| def init_test_case(self): | ||
| # self.groups = 1 |
There was a problem hiding this comment.
Remove these commented lines.
| for k in range(sub_out_c): | ||
| out[:, g * sub_out_c + k, d, i, j] = \ | ||
| np.sum(input_pad_masked * f_sub[k, :, :, :, :], | ||
| axis=(1, 2, 3,4)) |
There was a problem hiding this comment.
Add a space between 3, and 4
0155eb1 to
4f99b39
Compare
|
I think we can write conv2d and conv3d together. |
8f75b45 to
1bf8651
Compare
1bf8651 to
eafbbc1
Compare
typhoonzero
left a comment
There was a problem hiding this comment.
LGTM++
I approve this for now so it won't block following work, we can do the refine later.
|
Need to pull/rebase from develop to resolve the conflict. |
5d57f13 to
39945f7
Compare
39945f7 to
bf3ae06
Compare
c6a75ef to
4bc805b
Compare
e0f8a14 to
3b568c5
Compare
3b568c5 to
1724815
Compare
02871ed to
f302c6a
Compare
fix #4710