Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
a54565ea
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a54565ea
编写于
11月 10, 2017
作者:
X
xzl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete mask pool interface from poolprojection
上级
8106f414
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
38 addition
and
311 deletion
+38
-311
paddle/cuda/include/hl_cnn.h
paddle/cuda/include/hl_cnn.h
+2
-41
paddle/cuda/include/stub/hl_cnn_stub.h
paddle/cuda/include/stub/hl_cnn_stub.h
+1
-18
paddle/cuda/src/hl_cuda_cnn.cu
paddle/cuda/src/hl_cuda_cnn.cu
+4
-47
paddle/gserver/layers/PoolLayer.cpp
paddle/gserver/layers/PoolLayer.cpp
+4
-7
paddle/gserver/layers/PoolLayer.h
paddle/gserver/layers/PoolLayer.h
+0
-2
paddle/gserver/layers/PoolProjection.cpp
paddle/gserver/layers/PoolProjection.cpp
+2
-35
paddle/gserver/layers/PoolProjection.h
paddle/gserver/layers/PoolProjection.h
+0
-11
paddle/gserver/layers/PoolProjectionLayer.cpp
paddle/gserver/layers/PoolProjectionLayer.cpp
+1
-8
paddle/gserver/layers/Projection.h
paddle/gserver/layers/Projection.h
+0
-13
paddle/gserver/tests/test_MaxPoolingWithMaskOutput.cpp
paddle/gserver/tests/test_MaxPoolingWithMaskOutput.cpp
+13
-11
paddle/math/Matrix.cpp
paddle/math/Matrix.cpp
+7
-66
paddle/math/Matrix.h
paddle/math/Matrix.h
+4
-52
未找到文件。
paddle/cuda/include/hl_cnn.h
浏览文件 @
a54565ea
...
@@ -35,8 +35,7 @@ limitations under the License. */
...
@@ -35,8 +35,7 @@ limitations under the License. */
* @param[in] paddingW padding width.
* @param[in] paddingW padding width.
* @param[out] tgtData output data.
* @param[out] tgtData output data.
* @param[in] tgtStride stride between output data samples.
* @param[in] tgtStride stride between output data samples.
* @param[out] maskData the location indices of select max data
* @param[out] maskData the location indices of select max data.
* @param[in] withMask set true if output maskData
*/
*/
extern
void
hl_maxpool_forward
(
const
int
frameCnt
,
extern
void
hl_maxpool_forward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
real
*
inputData
,
...
@@ -53,45 +52,7 @@ extern void hl_maxpool_forward(const int frameCnt,
...
@@ -53,45 +52,7 @@ extern void hl_maxpool_forward(const int frameCnt,
const
int
paddingW
,
const
int
paddingW
,
real
*
tgtData
,
real
*
tgtData
,
const
int
tgtStride
,
const
int
tgtStride
,
real
*
maskData
,
real
*
maskData
=
NULL
);
bool
withMask
);
/**
* @brief Maximum pool forward.
*
* @param[in] frameCnt batch size of input image.
* @param[in] inputData input data.
* @param[in] channels number of channel.
* @param[in] height image height.
* @param[in] width image width.
* @param[in] pooledH output image height.
* @param[in] pooledW output image width.
* @param[in] sizeX width of pooling window.
* @param[in] sizeY height of pooling window.
* @param[in] strideH pooling stride height.
* @param[in] strideW pooling stride width.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[out] tgtData output data.
* @param[in] tgtStride stride between output data samples.
* @param[out] maskData the location indices of select max data
* @param[in] withMask set true if output maskData
*/
extern
void
hl_maxpool_forward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
int
channels
,
const
int
height
,
const
int
width
,
const
int
pooledH
,
const
int
pooledW
,
const
int
sizeX
,
const
int
sizeY
,
const
int
strideH
,
const
int
strideW
,
const
int
paddingH
,
const
int
paddingW
,
real
*
tgtData
,
const
int
tgtStride
);
/**
/**
* @brief Maximum pool backward.
* @brief Maximum pool backward.
...
...
paddle/cuda/include/stub/hl_cnn_stub.h
浏览文件 @
a54565ea
...
@@ -17,22 +17,6 @@ limitations under the License. */
...
@@ -17,22 +17,6 @@ limitations under the License. */
#include "hl_cnn.h"
#include "hl_cnn.h"
inline
void
hl_maxpool_forward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
int
channels
,
const
int
height
,
const
int
width
,
const
int
pooledH
,
const
int
pooledW
,
const
int
sizeX
,
const
int
sizeY
,
const
int
strideH
,
const
int
strideW
,
const
int
paddingH
,
const
int
paddingW
,
real
*
tgtData
,
const
int
tgtStride
)
{}
inline
void
hl_maxpool_forward
(
const
int
frameCnt
,
inline
void
hl_maxpool_forward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
real
*
inputData
,
const
int
channels
,
const
int
channels
,
...
@@ -48,8 +32,7 @@ inline void hl_maxpool_forward(const int frameCnt,
...
@@ -48,8 +32,7 @@ inline void hl_maxpool_forward(const int frameCnt,
const
int
paddingW
,
const
int
paddingW
,
real
*
tgtData
,
real
*
tgtData
,
const
int
tgtStride
,
const
int
tgtStride
,
real
*
MaskData
,
real
*
MaskData
=
NULL
)
{}
bool
withMask
)
{}
inline
void
hl_maxpool_backward
(
const
int
frameCnt
,
inline
void
hl_maxpool_backward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
real
*
inputData
,
...
...
paddle/cuda/src/hl_cuda_cnn.cu
浏览文件 @
a54565ea
...
@@ -32,8 +32,7 @@ __global__ void KeMaxPoolForward(const int nthreads,
...
@@ -32,8 +32,7 @@ __global__ void KeMaxPoolForward(const int nthreads,
const
int
offsetW
,
const
int
offsetW
,
real
*
tgtData
,
real
*
tgtData
,
const
int
tgtStride
,
const
int
tgtStride
,
real
*
maskData
,
real
*
maskData
)
{
bool
withMask
)
{
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
if
(
index
<
nthreads
)
{
if
(
index
<
nthreads
)
{
int
pw
=
index
%
pooledW
;
int
pw
=
index
%
pooledW
;
...
@@ -60,52 +59,12 @@ __global__ void KeMaxPoolForward(const int nthreads,
...
@@ -60,52 +59,12 @@ __global__ void KeMaxPoolForward(const int nthreads,
int
tgtIndex
=
int
tgtIndex
=
index
%
(
pooledW
*
pooledH
*
channels
)
+
frameNum
*
tgtStride
;
index
%
(
pooledW
*
pooledH
*
channels
)
+
frameNum
*
tgtStride
;
tgtData
[
tgtIndex
]
=
maxval
;
tgtData
[
tgtIndex
]
=
maxval
;
if
(
withMask
)
{
if
(
maskData
!=
NULL
)
{
maskData
[
tgtIndex
]
=
max_index
;
maskData
[
tgtIndex
]
=
max_index
;
}
}
}
}
}
}
void
hl_maxpool_forward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
int
channels
,
const
int
height
,
const
int
width
,
const
int
pooledH
,
const
int
pooledW
,
const
int
sizeX
,
const
int
sizeY
,
const
int
strideH
,
const
int
strideW
,
const
int
paddingH
,
const
int
paddingW
,
real
*
tgtData
,
const
int
tgtStride
)
{
int
num_kernels
=
pooledH
*
pooledW
*
channels
*
frameCnt
;
int
blocks
=
(
num_kernels
+
1024
-
1
)
/
1024
;
dim3
threads
(
1024
,
1
);
dim3
grid
(
blocks
,
1
);
KeMaxPoolForward
<<<
grid
,
threads
,
0
,
STREAM_DEFAULT
>>>
(
num_kernels
,
inputData
,
channels
,
height
,
width
,
pooledH
,
pooledW
,
sizeX
,
sizeY
,
strideH
,
strideW
,
paddingH
,
paddingW
,
tgtData
,
tgtStride
,
NULL
,
false
);
CHECK_SYNC
(
"hl_maxpool_forward failed"
);
}
void
hl_maxpool_forward
(
const
int
frameCnt
,
void
hl_maxpool_forward
(
const
int
frameCnt
,
const
real
*
inputData
,
const
real
*
inputData
,
const
int
channels
,
const
int
channels
,
...
@@ -121,8 +80,7 @@ void hl_maxpool_forward(const int frameCnt,
...
@@ -121,8 +80,7 @@ void hl_maxpool_forward(const int frameCnt,
const
int
paddingW
,
const
int
paddingW
,
real
*
tgtData
,
real
*
tgtData
,
const
int
tgtStride
,
const
int
tgtStride
,
real
*
maskData
,
real
*
maskData
)
{
bool
withMask
)
{
int
num_kernels
=
pooledH
*
pooledW
*
channels
*
frameCnt
;
int
num_kernels
=
pooledH
*
pooledW
*
channels
*
frameCnt
;
int
blocks
=
(
num_kernels
+
1024
-
1
)
/
1024
;
int
blocks
=
(
num_kernels
+
1024
-
1
)
/
1024
;
dim3
threads
(
1024
,
1
);
dim3
threads
(
1024
,
1
);
...
@@ -143,8 +101,7 @@ void hl_maxpool_forward(const int frameCnt,
...
@@ -143,8 +101,7 @@ void hl_maxpool_forward(const int frameCnt,
paddingW
,
paddingW
,
tgtData
,
tgtData
,
tgtStride
,
tgtStride
,
maskData
,
maskData
);
withMask
);
CHECK_SYNC
(
"hl_maxpool_forward failed"
);
CHECK_SYNC
(
"hl_maxpool_forward failed"
);
}
}
...
...
paddle/gserver/layers/PoolLayer.cpp
浏览文件 @
a54565ea
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "PoolLayer.h"
#include "PoolLayer.h"
#include "MaxPoolWithMaskLayer.h"
#include "PoolProjectionLayer.h"
#include "PoolProjectionLayer.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/Logging.h"
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
...
@@ -44,24 +45,20 @@ bool PoolLayer::init(const LayerMap& layerMap,
...
@@ -44,24 +45,20 @@ bool PoolLayer::init(const LayerMap& layerMap,
strideY_
=
conf
.
has_stride_y
()
?
conf
.
stride_y
()
:
conf
.
stride
();
strideY_
=
conf
.
has_stride_y
()
?
conf
.
stride_y
()
:
conf
.
stride
();
confPaddingY_
=
conf
.
has_padding_y
()
?
conf
.
padding_y
()
:
conf
.
padding
();
confPaddingY_
=
conf
.
has_padding_y
()
?
conf
.
padding_y
()
:
conf
.
padding
();
outputY_
=
conf
.
has_output_y
()
?
conf
.
output_y
()
:
conf
.
output_x
();
outputY_
=
conf
.
has_output_y
()
?
conf
.
output_y
()
:
conf
.
output_x
();
with_mask_
=
false
;
if
(
poolType_
==
"max-pool-with-mask"
)
{
setOutput
(
"mask"
,
&
mask_
);
with_mask_
=
true
;
}
return
true
;
return
true
;
}
}
Layer
*
PoolLayer
::
create
(
const
LayerConfig
&
config
)
{
Layer
*
PoolLayer
::
create
(
const
LayerConfig
&
config
)
{
CHECK_EQ
(
config
.
inputs_size
(),
1
);
CHECK_EQ
(
config
.
inputs_size
(),
1
);
const
std
::
string
&
pool
=
config
.
inputs
(
0
).
pool_conf
().
pool_type
();
const
std
::
string
&
pool
=
config
.
inputs
(
0
).
pool_conf
().
pool_type
();
if
(
pool
==
"max-projection"
||
pool
==
"avg-projection"
||
if
(
pool
==
"max-projection"
||
pool
==
"avg-projection"
)
{
pool
==
"max-pool-with-mask"
)
{
return
new
PoolProjectionLayer
(
config
);
return
new
PoolProjectionLayer
(
config
);
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
}
else
if
(
CudnnPoolLayer
::
typeCheck
(
pool
))
{
}
else
if
(
CudnnPoolLayer
::
typeCheck
(
pool
))
{
return
new
CudnnPoolLayer
(
config
);
return
new
CudnnPoolLayer
(
config
);
#endif
#endif
}
else
if
(
pool
==
"max-pool-with-mask"
)
{
return
new
MaxPoolWithMaskLayer
(
config
);
}
else
{
}
else
{
LOG
(
FATAL
)
<<
"Unknown pool type: "
<<
pool
;
LOG
(
FATAL
)
<<
"Unknown pool type: "
<<
pool
;
return
nullptr
;
return
nullptr
;
...
...
paddle/gserver/layers/PoolLayer.h
浏览文件 @
a54565ea
...
@@ -37,8 +37,6 @@ protected:
...
@@ -37,8 +37,6 @@ protected:
int
confPaddingY_
;
int
confPaddingY_
;
std
::
string
poolType_
;
std
::
string
poolType_
;
bool
with_mask_
;
Argument
mask_
;
public:
public:
explicit
PoolLayer
(
const
LayerConfig
&
config
)
:
Layer
(
config
)
{}
explicit
PoolLayer
(
const
LayerConfig
&
config
)
:
Layer
(
config
)
{}
...
...
paddle/gserver/layers/PoolProjection.cpp
浏览文件 @
a54565ea
...
@@ -36,10 +36,6 @@ PoolProjection::PoolProjection(const ProjectionConfig& config,
...
@@ -36,10 +36,6 @@ PoolProjection::PoolProjection(const ProjectionConfig& config,
strideY_
=
conf
.
has_stride_y
()
?
conf
.
stride_y
()
:
conf
.
stride
();
strideY_
=
conf
.
has_stride_y
()
?
conf
.
stride_y
()
:
conf
.
stride
();
confPaddingY_
=
conf
.
has_padding_y
()
?
conf
.
padding_y
()
:
conf
.
padding
();
confPaddingY_
=
conf
.
has_padding_y
()
?
conf
.
padding_y
()
:
conf
.
padding
();
outputY_
=
conf
.
has_output_y
()
?
conf
.
output_y
()
:
conf
.
output_x
();
outputY_
=
conf
.
has_output_y
()
?
conf
.
output_y
()
:
conf
.
output_x
();
with_mask_
=
false
;
if
(
poolType_
==
"max-pool-with-mask"
)
{
with_mask_
=
true
;
}
}
}
size_t
PoolProjection
::
getSize
()
{
size_t
PoolProjection
::
getSize
()
{
...
@@ -77,8 +73,6 @@ PoolProjection* PoolProjection::create(const ProjectionConfig& config,
...
@@ -77,8 +73,6 @@ PoolProjection* PoolProjection::create(const ProjectionConfig& config,
return
new
MaxPoolProjection
(
config
,
parameter
,
useGpu
);
return
new
MaxPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
if
(
pool
==
"avg-projection"
)
{
}
else
if
(
pool
==
"avg-projection"
)
{
return
new
AvgPoolProjection
(
config
,
parameter
,
useGpu
);
return
new
AvgPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
if
(
pool
==
"max-pool-with-mask"
)
{
return
new
MaxPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
{
}
else
{
LOG
(
FATAL
)
<<
"Unknown pool type: "
<<
pool
;
LOG
(
FATAL
)
<<
"Unknown pool type: "
<<
pool
;
return
nullptr
;
return
nullptr
;
...
@@ -90,10 +84,7 @@ void MaxPoolProjection::forward() {
...
@@ -90,10 +84,7 @@ void MaxPoolProjection::forward() {
CHECK_EQ
(
width
,
out_
->
value
->
getWidth
());
CHECK_EQ
(
width
,
out_
->
value
->
getWidth
());
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
maskV
=
out_
->
value
;
if
(
with_mask_
)
{
maskV
=
mask_
->
value
;
}
outV
->
maxPoolForward
(
*
inputV
,
outV
->
maxPoolForward
(
*
inputV
,
imgSizeY_
,
imgSizeY_
,
imgSize_
,
imgSize_
,
...
@@ -105,9 +96,7 @@ void MaxPoolProjection::forward() {
...
@@ -105,9 +96,7 @@ void MaxPoolProjection::forward() {
outputY_
,
outputY_
,
outputX_
,
outputX_
,
confPaddingY_
,
confPaddingY_
,
confPadding_
,
confPadding_
);
maskV
,
with_mask_
);
}
}
void
MaxPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
void
MaxPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
...
@@ -180,26 +169,4 @@ void AvgPoolProjection::backward(const UpdateCallback& callback) {
...
@@ -180,26 +169,4 @@ void AvgPoolProjection::backward(const UpdateCallback& callback) {
confPaddingY_
,
confPaddingY_
,
confPadding_
);
confPadding_
);
}
}
void
MaxWithMaskPoolProjection
::
forward
()
{
size_t
width
=
getSize
();
CHECK_EQ
(
width
,
out_
->
value
->
getWidth
());
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
maskV
=
mask_
->
value
;
outV
->
maxPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
channels_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputY_
,
outputX_
,
confPaddingY_
,
confPadding_
,
maskV
,
with_mask_
);
}
}
// namespace paddle
}
// namespace paddle
paddle/gserver/layers/PoolProjection.h
浏览文件 @
a54565ea
...
@@ -28,7 +28,6 @@ protected:
...
@@ -28,7 +28,6 @@ protected:
int
confPaddingY_
,
confPadding_
;
int
confPaddingY_
,
confPadding_
;
size_t
channels_
;
size_t
channels_
;
std
::
string
poolType_
;
std
::
string
poolType_
;
bool
with_mask_
;
public:
public:
PoolProjection
(
const
ProjectionConfig
&
config
,
PoolProjection
(
const
ProjectionConfig
&
config
,
...
@@ -65,14 +64,4 @@ public:
...
@@ -65,14 +64,4 @@ public:
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
};
class
MaxWithMaskPoolProjection
:
public
MaxPoolProjection
{
public:
MaxWithMaskPoolProjection
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
:
MaxPoolProjection
(
config
,
parameter
,
useGpu
)
{}
virtual
void
forward
();
};
}
// namespace paddle
}
// namespace paddle
paddle/gserver/layers/PoolProjectionLayer.cpp
浏览文件 @
a54565ea
...
@@ -52,15 +52,8 @@ void PoolProjectionLayer::forward(PassType passType) {
...
@@ -52,15 +52,8 @@ void PoolProjectionLayer::forward(PassType passType) {
int
batchSize
=
in
.
value
->
getHeight
();
int
batchSize
=
in
.
value
->
getHeight
();
int
size
=
getSize
();
int
size
=
getSize
();
if
(
with_mask_
)
{
resetSpecifyOutput
(
mask_
,
batchSize
,
size
,
/* isValueClean */
false
,
/* isGradClean */
true
);
}
resetOutput
(
batchSize
,
size
);
resetOutput
(
batchSize
,
size
);
poolProjection_
->
forward
(
&
in
,
&
output_
,
&
mask_
,
passType
);
poolProjection_
->
forward
(
&
in
,
&
output_
,
passType
);
}
}
void
PoolProjectionLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
void
PoolProjectionLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
...
...
paddle/gserver/layers/Projection.h
浏览文件 @
a54565ea
...
@@ -69,17 +69,6 @@ public:
...
@@ -69,17 +69,6 @@ public:
forward
();
forward
();
}
}
void
forward
(
const
Argument
*
in
,
const
Argument
*
out
,
const
Argument
*
mask
,
PassType
passType
)
{
in_
=
in
;
out_
=
out
;
mask_
=
mask
;
passType_
=
passType
;
forward
();
}
virtual
void
prefetch
(
const
Argument
*
in
)
{}
virtual
void
prefetch
(
const
Argument
*
in
)
{}
virtual
void
forward
()
=
0
;
virtual
void
forward
()
=
0
;
virtual
void
backward
(
const
UpdateCallback
&
callback
)
=
0
;
virtual
void
backward
(
const
UpdateCallback
&
callback
)
=
0
;
...
@@ -141,8 +130,6 @@ protected:
...
@@ -141,8 +130,6 @@ protected:
const
Argument
*
in_
;
const
Argument
*
in_
;
/// Store `out` passed to forward()
/// Store `out` passed to forward()
const
Argument
*
out_
;
const
Argument
*
out_
;
/// Store `mask` passed to forward()
const
Argument
*
mask_
;
/// Store `passType` passed to forward()
/// Store `passType` passed to forward()
PassType
passType_
;
PassType
passType_
;
/// Layer forward function
/// Layer forward function
...
...
paddle/gserver/tests/test_MaxPoolingWithMaskOutput.cpp
浏览文件 @
a54565ea
...
@@ -68,7 +68,7 @@ void doOneMaxPoolingWithMaskOutputTest(MatrixPtr& inputMat,
...
@@ -68,7 +68,7 @@ void doOneMaxPoolingWithMaskOutputTest(MatrixPtr& inputMat,
std
::
vector
<
DataLayerPtr
>
dataLayers
;
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
vector
<
Argument
>
datas
;
;
initDataLayer
(
config
,
initDataLayer
(
config
,
&
dataLayers
,
&
dataLayers
,
&
datas
,
&
datas
,
...
@@ -85,7 +85,7 @@ void doOneMaxPoolingWithMaskOutputTest(MatrixPtr& inputMat,
...
@@ -85,7 +85,7 @@ void doOneMaxPoolingWithMaskOutputTest(MatrixPtr& inputMat,
LayerPtr
maxPoolingWithMaskOutputLayer
;
LayerPtr
maxPoolingWithMaskOutputLayer
;
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
maxPoolingWithMaskOutputLayer
);
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
maxPoolingWithMaskOutputLayer
);
maxPoolingWithMaskOutputLayer
->
forward
(
PASS_GC
);
maxPoolingWithMaskOutputLayer
->
forward
(
PASS_GC
);
;
checkMatrixEqual
(
maxPoolingWithMaskOutputLayer
->
getOutput
(
"mask"
).
value
,
checkMatrixEqual
(
maxPoolingWithMaskOutputLayer
->
getOutput
(
"mask"
).
value
,
maskMat
);
maskMat
);
}
}
...
@@ -105,7 +105,8 @@ TEST(Layer, maxPoolingWithMaskOutputLayerFwd) {
...
@@ -105,7 +105,8 @@ TEST(Layer, maxPoolingWithMaskOutputLayerFwd) {
maskMat
->
setData
(
maskData
);
maskMat
->
setData
(
maskData
);
doOneMaxPoolingWithMaskOutputTest
(
doOneMaxPoolingWithMaskOutputTest
(
inputMat
,
"max-pool-with-mask"
,
useGpu
,
maskMat
);
inputMat
,
"max-pool-with-mask"
,
useGpu
,
maskMat
);
#ifdef PADDLE_WITH_CUDA
/*
#ifdef PADDLE_WITH_CUDA
useGpu = true;
useGpu = true;
inputMat = Matrix::create(1, 25, false, useGpu);
inputMat = Matrix::create(1, 25, false, useGpu);
maskMat = Matrix::create(1, 4, false, useGpu);
maskMat = Matrix::create(1, 4, false, useGpu);
...
@@ -113,5 +114,6 @@ TEST(Layer, maxPoolingWithMaskOutputLayerFwd) {
...
@@ -113,5 +114,6 @@ TEST(Layer, maxPoolingWithMaskOutputLayerFwd) {
maskMat->copyFrom(maskData, 4);
maskMat->copyFrom(maskData, 4);
doOneMaxPoolingWithMaskOutputTest(
doOneMaxPoolingWithMaskOutputTest(
inputMat, "max-pool-with-mask", useGpu, maskMat);
inputMat, "max-pool-with-mask", useGpu, maskMat);
#endif
#endif
*/
}
}
paddle/math/Matrix.cpp
浏览文件 @
a54565ea
...
@@ -1017,34 +1017,6 @@ void GpuMatrix::check(std::ostream& os, Matrix& refMat, bool printDiff) {
...
@@ -1017,34 +1017,6 @@ void GpuMatrix::check(std::ostream& os, Matrix& refMat, bool printDiff) {
LOG
(
INFO
)
<<
"the diffCnt is "
<<
diffCnt
;
LOG
(
INFO
)
<<
"the diffCnt is "
<<
diffCnt
;
}
}
void
GpuMatrix
::
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
channels
,
size_t
sizeX
,
size_t
sizeY
,
size_t
strideH
,
size_t
strideW
,
size_t
outputH
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingW
)
{
maxPoolForward
(
inputMat
,
imgSizeH
,
imgSizeW
,
channels
,
sizeX
,
sizeY
,
strideH
,
strideW
,
outputH
,
outputW
,
paddingH
,
paddingW
,
NULL
,
false
);
}
void
GpuMatrix
::
maxPoolForward
(
Matrix
&
inputMat
,
void
GpuMatrix
::
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
imgSizeW
,
...
@@ -1057,8 +1029,7 @@ void GpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -1057,8 +1029,7 @@ void GpuMatrix::maxPoolForward(Matrix& inputMat,
size_t
outputW
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingH
,
size_t
paddingW
,
size_t
paddingW
,
MatrixPtr
maskMatP
,
MatrixPtr
maskMatP
)
{
bool
withMask
)
{
CHECK
(
inputMat
.
useGpu_
==
true
)
<<
"Matrix type are not equal"
;
CHECK
(
inputMat
.
useGpu_
==
true
)
<<
"Matrix type are not equal"
;
real
*
inputData
=
inputMat
.
getData
();
real
*
inputData
=
inputMat
.
getData
();
...
@@ -1068,7 +1039,7 @@ void GpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -1068,7 +1039,7 @@ void GpuMatrix::maxPoolForward(Matrix& inputMat,
CHECK
(
height_
==
inputMat
.
getHeight
());
CHECK
(
height_
==
inputMat
.
getHeight
());
CHECK
(
width_
==
outputH
*
outputW
*
channels
);
CHECK
(
width_
==
outputH
*
outputW
*
channels
);
if
(
withMask
)
{
if
(
maskMatP
!=
NULL
)
{
CHECK
(
maskMatP
->
useGpu_
==
true
)
<<
"Matrix type are not equal"
;
CHECK
(
maskMatP
->
useGpu_
==
true
)
<<
"Matrix type are not equal"
;
CHECK
(
outputH
*
outputW
*
channels
==
maskMatP
->
getWidth
());
CHECK
(
outputH
*
outputW
*
channels
==
maskMatP
->
getWidth
());
maskData
=
maskMatP
->
getData
();
maskData
=
maskMatP
->
getData
();
...
@@ -1089,8 +1060,7 @@ void GpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -1089,8 +1060,7 @@ void GpuMatrix::maxPoolForward(Matrix& inputMat,
paddingW
,
paddingW
,
data_
,
data_
,
getStride
(),
getStride
(),
maskData
,
maskData
);
withMask
);
}
}
void
GpuMatrix
::
maxPoolBackward
(
Matrix
&
inputMat
,
void
GpuMatrix
::
maxPoolBackward
(
Matrix
&
inputMat
,
...
@@ -2001,34 +1971,6 @@ void CpuMatrix::inverse(MatrixPtr& matInv, bool memAlloc) {
...
@@ -2001,34 +1971,6 @@ void CpuMatrix::inverse(MatrixPtr& matInv, bool memAlloc) {
CHECK_EQ
(
info
,
0
);
CHECK_EQ
(
info
,
0
);
}
}
void
CpuMatrix
::
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
channels
,
size_t
sizeX
,
size_t
sizeY
,
size_t
strideH
,
size_t
strideW
,
size_t
outputH
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingW
)
{
maxPoolForward
(
inputMat
,
imgSizeH
,
imgSizeW
,
channels
,
sizeX
,
sizeY
,
strideH
,
strideW
,
outputH
,
outputW
,
paddingH
,
paddingW
,
NULL
,
false
);
}
void
CpuMatrix
::
maxPoolForward
(
Matrix
&
inputMat
,
void
CpuMatrix
::
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
imgSizeW
,
...
@@ -2041,8 +1983,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -2041,8 +1983,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
size_t
outputW
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingH
,
size_t
paddingW
,
size_t
paddingW
,
MatrixPtr
maskMatP
,
MatrixPtr
maskMatP
)
{
bool
withMask
)
{
real
*
inputData
=
inputMat
.
getData
();
real
*
inputData
=
inputMat
.
getData
();
real
*
outData
=
data_
;
real
*
outData
=
data_
;
real
*
maskData
=
NULL
;
real
*
maskData
=
NULL
;
...
@@ -2054,7 +1995,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -2054,7 +1995,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
CHECK_EQ
(
channels
*
outLength
,
this
->
getWidth
());
CHECK_EQ
(
channels
*
outLength
,
this
->
getWidth
());
size_t
outStride
=
getStride
();
size_t
outStride
=
getStride
();
if
(
withMask
)
{
if
(
maskMatP
!=
NULL
)
{
maskData
=
maskMatP
->
getData
();
maskData
=
maskMatP
->
getData
();
CHECK_EQ
(
channels
*
outLength
,
maskMatP
->
getWidth
());
CHECK_EQ
(
channels
*
outLength
,
maskMatP
->
getWidth
());
}
}
...
@@ -2080,7 +2021,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -2080,7 +2021,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
int
wstart
=
pw
*
strideW
-
paddingW
;
int
wstart
=
pw
*
strideW
-
paddingW
;
int
wend
=
std
::
min
(
wstart
+
sizeX
,
imgSizeW
);
int
wend
=
std
::
min
(
wstart
+
sizeX
,
imgSizeW
);
wstart
=
std
::
max
(
wstart
,
0
);
wstart
=
std
::
max
(
wstart
,
0
);
if
(
!
withMask
)
{
if
(
maskMatP
==
NULL
)
{
for
(
int
h
=
hstart
;
h
<
hend
;
++
h
)
{
for
(
int
h
=
hstart
;
h
<
hend
;
++
h
)
{
for
(
int
w
=
wstart
;
w
<
wend
;
++
w
)
{
for
(
int
w
=
wstart
;
w
<
wend
;
++
w
)
{
outData
[
ph
*
outputW
+
pw
]
=
std
::
max
(
outData
[
ph
*
outputW
+
pw
]
=
std
::
max
(
...
@@ -2103,7 +2044,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
...
@@ -2103,7 +2044,7 @@ void CpuMatrix::maxPoolForward(Matrix& inputMat,
inputData
+=
inLength
;
inputData
+=
inLength
;
outData
+=
outLength
;
outData
+=
outLength
;
if
(
withMask
)
maskData
+=
outLength
;
if
(
maskMatP
!=
NULL
)
maskData
+=
outLength
;
}
}
}
}
}
}
...
...
paddle/math/Matrix.h
浏览文件 @
a54565ea
...
@@ -861,26 +861,7 @@ public:
...
@@ -861,26 +861,7 @@ public:
/**
/**
* Pooling forward operation, pick out the largest element
* Pooling forward operation, pick out the largest element
* in the sizeX of value.
* in the sizeX of value, if the maskMatP is not NULL, it will
*/
virtual
void
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
channels
,
size_t
sizeX
,
size_t
sizeY
,
size_t
strideH
,
size_t
strideW
,
size_t
outputH
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingW
)
{
LOG
(
FATAL
)
<<
"Not implemeted"
;
}
/**
* Pooling forward operation, pick out the largest element
* in the sizeX of value, if set withMask true, it will
* also caculate the location indices.
* also caculate the location indices.
*/
*/
virtual
void
maxPoolForward
(
Matrix
&
inputMat
,
virtual
void
maxPoolForward
(
Matrix
&
inputMat
,
...
@@ -895,8 +876,7 @@ public:
...
@@ -895,8 +876,7 @@ public:
size_t
outputW
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingH
,
size_t
paddingW
,
size_t
paddingW
,
MatrixPtr
maskMatP
,
MatrixPtr
maskMatP
=
NULL
)
{
bool
withMask
)
{
LOG
(
FATAL
)
<<
"Not implemeted"
;
LOG
(
FATAL
)
<<
"Not implemeted"
;
}
}
...
@@ -1437,19 +1417,6 @@ public:
...
@@ -1437,19 +1417,6 @@ public:
void
classificationError
(
Matrix
&
output
,
IVector
&
label
,
size_t
topkSize
=
1
);
void
classificationError
(
Matrix
&
output
,
IVector
&
label
,
size_t
topkSize
=
1
);
void
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
channels
,
size_t
sizeX
,
size_t
sizeY
,
size_t
strideH
,
size_t
strideW
,
size_t
outputH
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingW
);
void
maxPoolForward
(
Matrix
&
inputMat
,
void
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
imgSizeW
,
...
@@ -1462,8 +1429,7 @@ public:
...
@@ -1462,8 +1429,7 @@ public:
size_t
outputW
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingH
,
size_t
paddingW
,
size_t
paddingW
,
MatrixPtr
maskMatP
,
MatrixPtr
maskMatP
);
bool
withMask
);
void
maxPoolBackward
(
Matrix
&
image
,
void
maxPoolBackward
(
Matrix
&
image
,
size_t
imgSizeH
,
size_t
imgSizeH
,
...
@@ -1723,19 +1689,6 @@ public:
...
@@ -1723,19 +1689,6 @@ public:
MatrixPtr
clone
(
size_t
height
,
size_t
width
,
bool
useGpu
=
false
);
MatrixPtr
clone
(
size_t
height
,
size_t
width
,
bool
useGpu
=
false
);
void
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
channels
,
size_t
sizeX
,
size_t
sizeY
,
size_t
strideH
,
size_t
strideW
,
size_t
outputH
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingW
);
void
maxPoolForward
(
Matrix
&
inputMat
,
void
maxPoolForward
(
Matrix
&
inputMat
,
size_t
imgSizeH
,
size_t
imgSizeH
,
size_t
imgSizeW
,
size_t
imgSizeW
,
...
@@ -1748,8 +1701,7 @@ public:
...
@@ -1748,8 +1701,7 @@ public:
size_t
outputW
,
size_t
outputW
,
size_t
paddingH
,
size_t
paddingH
,
size_t
paddingW
,
size_t
paddingW
,
MatrixPtr
maskMatP
,
MatrixPtr
maskMatP
);
bool
withMask
);
void
maxPoolBackward
(
Matrix
&
image
,
void
maxPoolBackward
(
Matrix
&
image
,
size_t
imgSizeH
,
size_t
imgSizeH
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录