Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
53e1629a
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看板
提交
53e1629a
编写于
11月 08, 2016
作者:
W
wangyang59
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored imageSize in ConvBaseLayer to MathUtil
上级
03f4b1d4
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
39 addition
and
62 deletion
+39
-62
paddle/gserver/layers/ConvBaseLayer.cpp
paddle/gserver/layers/ConvBaseLayer.cpp
+9
-4
paddle/gserver/layers/ConvBaseLayer.h
paddle/gserver/layers/ConvBaseLayer.h
+0
-37
paddle/gserver/tests/test_ConvTrans.cpp
paddle/gserver/tests/test_ConvTrans.cpp
+7
-9
paddle/gserver/tests/test_LayerGrad.cpp
paddle/gserver/tests/test_LayerGrad.cpp
+3
-4
paddle/math/MathUtils.cpp
paddle/math/MathUtils.cpp
+13
-0
paddle/math/MathUtils.h
paddle/math/MathUtils.h
+3
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+4
-8
未找到文件。
paddle/gserver/layers/ConvBaseLayer.cpp
浏览文件 @
53e1629a
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/utils/Logging.h"
#include "ConvBaseLayer.h"
#include "paddle/math/MathUtils.h"
namespace
paddle
{
bool
ConvBaseLayer
::
init
(
const
LayerMap
&
layerMap
,
...
...
@@ -95,18 +96,22 @@ size_t ConvBaseLayer::calOutputSize() {
if
(
inW
[
i
]
==
0
)
inW
[
i
]
=
config_
.
inputs
(
i
).
conv_conf
().
output_x
();
outH
.
push_back
(
imageSize
(
inH
[
i
],
filterSizeY_
[
i
],
paddingY_
[
i
],
strideY_
[
i
]));
imageSize
(
inH
[
i
],
filterSizeY_
[
i
],
paddingY_
[
i
],
strideY_
[
i
],
caffeMode_
));
outW
.
push_back
(
imageSize
(
inW
[
i
],
filterSize_
[
i
],
padding_
[
i
],
stride_
[
i
]));
imageSize
(
inW
[
i
],
filterSize_
[
i
],
padding_
[
i
],
stride_
[
i
],
caffeMode_
));
}
else
{
if
(
inH
[
i
]
==
0
)
inH
[
i
]
=
config_
.
inputs
(
i
).
conv_conf
().
img_size
();
if
(
inW
[
i
]
==
0
)
inW
[
i
]
=
config_
.
inputs
(
i
).
conv_conf
().
img_size
();
outH
.
push_back
(
outputSize
(
inH
[
i
],
filterSizeY_
[
i
],
paddingY_
[
i
],
strideY_
[
i
]));
outputSize
(
inH
[
i
],
filterSizeY_
[
i
],
paddingY_
[
i
],
strideY_
[
i
],
caffeMode_
));
outW
.
push_back
(
outputSize
(
inW
[
i
],
filterSize_
[
i
],
padding_
[
i
],
stride_
[
i
]));
outputSize
(
inW
[
i
],
filterSize_
[
i
],
padding_
[
i
],
stride_
[
i
],
caffeMode_
));
}
CHECK_EQ
(
outH
[
i
],
outH
[
0
]);
CHECK_EQ
(
outW
[
i
],
outW
[
0
]);
...
...
paddle/gserver/layers/ConvBaseLayer.h
浏览文件 @
53e1629a
...
...
@@ -91,43 +91,6 @@ public:
virtual
size_t
calOutputSize
();
Weight
&
getWeight
(
int
idx
)
{
return
*
weights_
[
idx
];
}
/**
* Calculate output size based on caffeMode_.
* - input(+padding): 0123456789
* - imageSize(+padding) = 10;
* - filterSize = 3;
* - stride = 2;
* - caffeMode_ is true:
- output: (012), (234), (456), (678)
- outputSize = 4;
* - caffeMode_ is false:
* - output: (012), (234), (456), (678), (9)
* - outputSize = 5;
*/
int
outputSize
(
int
imageSize
,
int
filterSize
,
int
padding
,
int
stride
)
{
int
outputSize
;
if
(
!
caffeMode_
)
{
outputSize
=
(
imageSize
-
filterSize
+
2
*
padding
+
stride
-
1
)
/
stride
+
1
;
}
else
{
outputSize
=
(
imageSize
-
filterSize
+
2
*
padding
)
/
stride
+
1
;
}
CHECK_GE
(
outputSize
,
1
);
return
outputSize
;
}
int
imageSize
(
int
outputSize
,
int
filterSize
,
int
padding
,
int
stride
)
{
int
imageSize
;
if
(
!
caffeMode_
)
{
imageSize
=
(
outputSize
-
1
)
*
stride
+
filterSize
-
2
*
padding
-
stride
+
1
;
}
else
{
imageSize
=
(
outputSize
-
1
)
*
stride
+
filterSize
-
2
*
padding
;
}
CHECK_GE
(
imageSize
,
1
);
return
imageSize
;
}
};
}
// namespace paddle
paddle/gserver/tests/test_ConvTrans.cpp
浏览文件 @
53e1629a
...
...
@@ -20,6 +20,7 @@ limitations under the License. */
#include "paddle/trainer/Trainer.h"
#include "paddle/utils/GlobalConstants.h"
#include "paddle/gserver/layers/ExpandConvTransLayer.h"
#include "paddle/math/MathUtils.h"
#include "TestUtil.h"
#include "LayerGradUtil.h"
...
...
@@ -56,11 +57,9 @@ TEST(Layer, convTransLayerFwd) {
conv
->
set_groups
(
1
);
conv
->
set_filter_channels
(
3
/
conv
->
groups
());
conv
->
set_img_size
(
16
);
conv
->
set_output_x
(
(
2
*
conv
->
padding
()
+
conv
->
img_size
()
-
conv
->
filter_size
())
/
((
float
)
conv
->
stride
())
+
1.5
);
conv
->
set_output_x
(
outputSize
(
conv
->
img_size
(),
conv
->
filter_size
(),
conv
->
padding
(),
conv
->
stride
(),
/* caffeMode */
true
));
configt
.
layerConfig
.
set_size
(
conv
->
img_size
()
*
conv
->
img_size
()
*
configt
.
layerConfig
.
num_filters
());
configt
.
layerConfig
.
set_name
(
"convTrans"
);
...
...
@@ -99,10 +98,9 @@ TEST(Layer, convTransLayerFwd) {
conv
->
set_groups
(
1
);
conv
->
set_filter_channels
(
conv
->
channels
()
/
conv
->
groups
());
conv
->
set_img_size
(
16
);
conv
->
set_output_x
(
(
2
*
conv
->
padding
()
+
conv
->
img_size
()
-
conv
->
filter_size
())
/
((
float
)
conv
->
stride
())
+
1.5
);
conv
->
set_output_x
(
outputSize
(
conv
->
img_size
(),
conv
->
filter_size
(),
conv
->
padding
(),
conv
->
stride
(),
/* caffeMode */
true
));
config
.
layerConfig
.
set_size
(
conv
->
output_x
()
*
conv
->
output_x
()
*
config
.
layerConfig
.
num_filters
());
config
.
layerConfig
.
set_name
(
"conv"
);
...
...
paddle/gserver/tests/test_LayerGrad.cpp
浏览文件 @
53e1629a
...
...
@@ -336,10 +336,9 @@ void testConvTransLayer(const string& type, bool trans, bool useGpu) {
conv
->
set_groups
(
1
);
conv
->
set_filter_channels
(
3
/
conv
->
groups
());
conv
->
set_img_size
(
16
);
conv
->
set_output_x
(
(
2
*
conv
->
padding
()
+
conv
->
img_size
()
-
conv
->
filter_size
())
/
((
float
)
conv
->
stride
())
+
1.5
);
conv
->
set_output_x
(
outputSize
(
conv
->
img_size
(),
conv
->
filter_size
(),
conv
->
padding
(),
conv
->
stride
(),
/* caffeMode */
true
));
config
.
layerConfig
.
set_size
(
conv
->
img_size
()
*
conv
->
img_size
()
*
config
.
layerConfig
.
num_filters
());
...
...
paddle/math/MathUtils.cpp
浏览文件 @
53e1629a
...
...
@@ -80,4 +80,17 @@ int outputSize(int imageSize, int filterSize, int padding, int stride,
return
outputSize
;
}
int
imageSize
(
int
outputSize
,
int
filterSize
,
int
padding
,
int
stride
,
bool
caffeMode
)
{
int
imageSize
;
if
(
!
caffeMode
)
{
imageSize
=
(
outputSize
-
1
)
*
stride
+
filterSize
-
2
*
padding
-
stride
+
1
;
}
else
{
imageSize
=
(
outputSize
-
1
)
*
stride
+
filterSize
-
2
*
padding
;
}
CHECK_GE
(
imageSize
,
1
);
return
imageSize
;
}
}
// namespace paddle
paddle/math/MathUtils.h
浏览文件 @
53e1629a
...
...
@@ -60,4 +60,7 @@ void sparseRand(int* major, int* minor, int nnz, int majorLen, int minorMax,
int
outputSize
(
int
imageSize
,
int
filterSize
,
int
padding
,
int
stride
,
bool
caffeMode
);
int
imageSize
(
int
outputSize
,
int
filterSize
,
int
padding
,
int
stride
,
bool
caffeMode
);
}
// namespace paddle
python/paddle/trainer/config_parser.py
浏览文件 @
53e1629a
...
...
@@ -1107,14 +1107,10 @@ def parse_conv(conv, input_layer_name, conv_conf, trans=False):
(
"Input layer %s: Incorrect input image size %d for input "
+
"image pixels %d"
)
%
(
input_layer_name
,
conv_conf
.
img_size
,
img_pixels
))
if
conv
.
caffe_mode
:
conv_conf
.
output_x
=
\
1
+
int
(
math
.
floor
((
2
*
conv
.
padding
+
conv_conf
.
img_size
\
-
conv
.
filter_size
)
/
float
(
conv
.
stride
)))
else
:
conv_conf
.
output_x
=
\
1
+
int
(
math
.
ceil
((
2
*
conv
.
padding
+
conv_conf
.
img_size
\
-
conv
.
filter_size
)
/
float
(
conv
.
stride
)))
conv_conf
.
output_x
=
cnn_output_size
(
conv_conf
.
img_size
,
conv_conf
.
filter_size
,
conv_conf
.
padding
,
conv_conf
.
stride
,
conv_conf
.
caffe_mode
)
else
:
outputSize
=
g_layer_map
[
input_layer_name
].
size
/
conv
.
channels
print
(
'channels=%d size=%d'
%
(
conv
.
channels
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录