Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
9a1b5df0
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9a1b5df0
编写于
11月 07, 2018
作者:
K
kechxu
提交者:
Jiangtao Hu
12月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prediction: implement max pool 1d and avg pool 1d
上级
04d27ee9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
128 addition
and
10 deletion
+128
-10
modules/prediction/network/net_layer.cc
modules/prediction/network/net_layer.cc
+97
-2
modules/prediction/network/net_layer.h
modules/prediction/network/net_layer.h
+25
-2
modules/prediction/proto/cruise_model.proto
modules/prediction/proto/cruise_model.proto
+2
-2
modules/prediction/proto/network_layers.proto
modules/prediction/proto/network_layers.proto
+4
-4
未找到文件。
modules/prediction/network/net_layer.cc
浏览文件 @
9a1b5df0
...
...
@@ -20,6 +20,9 @@
#include "modules/prediction/network/net_layer.h"
#include <algorithm>
#include <limits>
#include "cyber/common/log.h"
namespace
apollo
{
...
...
@@ -28,6 +31,8 @@ namespace network {
using
apollo
::
prediction
::
DenseParameter
;
using
apollo
::
prediction
::
LayerParameter
;
using
apollo
::
prediction
::
Conv1dParameter
;
using
apollo
::
prediction
::
MaxPool1dParameter
;
bool
Layer
::
Load
(
const
LayerParameter
&
layer_pb
)
{
if
(
!
layer_pb
.
has_name
())
{
...
...
@@ -93,6 +98,10 @@ bool Conv1d::Load(const LayerParameter& layer_pb) {
return
false
;
}
Conv1dParameter
conv1d_pb
=
layer_pb
.
conv1d
();
return
Load
(
conv1d_pb
);
}
bool
Conv1d
::
Load
(
const
Conv1dParameter
&
conv1d_pb
)
{
if
(
!
conv1d_pb
.
has_kernel
()
||
!
LoadTensor
(
conv1d_pb
.
kernel
(),
&
kernel_
))
{
AERROR
<<
"Fail to Load kernel!"
;
...
...
@@ -120,7 +129,7 @@ bool Conv1d::Load(const LayerParameter& layer_pb) {
}
void
Conv1d
::
Run
(
const
std
::
vector
<
Eigen
::
MatrixXf
>&
inputs
,
Eigen
::
MatrixXf
*
output
)
{
Eigen
::
MatrixXf
*
output
)
{
CHECK_EQ
(
inputs
.
size
(),
1
);
CHECK_GT
(
kernel_
.
size
(),
0
);
CHECK_EQ
(
kernel_
[
0
].
rows
(),
inputs
[
0
].
rows
());
...
...
@@ -130,7 +139,7 @@ void Conv1d::Run(const std::vector<Eigen::MatrixXf>& inputs,
output
->
resize
(
output_num_row
,
output_num_col
);
for
(
int
i
=
0
;
i
<
output_num_col
;
++
i
)
{
for
(
int
j
=
0
;
j
+
kernel_size
<
inputs
[
0
].
cols
();
j
+=
stride_
)
{
double
output_i_j
=
0.0
;
float
output_i_j
=
0.0
;
for
(
int
p
=
0
;
p
<
inputs
[
0
].
rows
();
++
p
)
{
for
(
int
q
=
j
;
q
<
j
+
kernel_size
;
++
q
)
{
output_i_j
+=
inputs
[
0
](
p
,
q
)
*
kernel_
[
i
](
p
,
q
-
j
);
...
...
@@ -141,6 +150,92 @@ void Conv1d::Run(const std::vector<Eigen::MatrixXf>& inputs,
}
}
bool
MaxPool1d
::
Load
(
const
LayerParameter
&
layer_pb
)
{
if
(
!
Layer
::
Load
(
layer_pb
))
{
AERROR
<<
"Fail to Load LayerParameter!"
;
return
false
;
}
MaxPool1dParameter
maxpool1d_pb
=
layer_pb
.
maxpool1d
();
return
Load
(
maxpool1d_pb
);
return
true
;
}
bool
MaxPool1d
::
Load
(
const
MaxPool1dParameter
&
maxpool1d_pb
)
{
CHECK
(
maxpool1d_pb
.
has_kernel_size
());
CHECK_GT
(
maxpool1d_pb
.
has_kernel_size
(),
0
);
kernel_size_
=
maxpool1d_pb
.
kernel_size
();
if
(
maxpool1d_pb
.
has_stride
()
&&
maxpool1d_pb
.
stride
()
>
0
)
{
stride_
=
maxpool1d_pb
.
stride
();
}
else
{
ADEBUG
<<
"No valid stride found, use kernel size, instead"
;
stride_
=
maxpool1d_pb
.
kernel_size
();
}
return
true
;
}
void
MaxPool1d
::
Run
(
const
std
::
vector
<
Eigen
::
MatrixXf
>&
inputs
,
Eigen
::
MatrixXf
*
output
)
{
CHECK_EQ
(
inputs
.
size
(),
1
);
int
output_num_col
=
(
inputs
[
0
].
cols
()
-
kernel_size_
)
/
stride_
+
1
;
int
output_num_row
=
inputs
[
0
].
rows
();
output
->
resize
(
output_num_row
,
output_num_col
);
int
input_index
=
0
;
for
(
int
j
=
0
;
j
<
output_num_col
;
++
j
)
{
CHECK_LT
(
input_index
+
kernel_size_
,
inputs
[
0
].
cols
());
for
(
int
i
=
0
;
i
<
output_num_row
;
++
i
)
{
float
output_i_j
=
-
std
::
numeric_limits
<
float
>::
infinity
();
for
(
int
k
=
input_index
;
k
<
input_index
+
kernel_size_
;
++
k
)
{
output_i_j
=
std
::
max
(
output_i_j
,
inputs
[
0
](
i
,
k
));
}
(
*
output
)(
i
,
j
)
=
output_i_j
;
}
input_index
+=
stride_
;
}
}
bool
AvgPool1d
::
Load
(
const
LayerParameter
&
layer_pb
)
{
if
(
!
Layer
::
Load
(
layer_pb
))
{
AERROR
<<
"Fail to Load LayerParameter!"
;
return
false
;
}
AvgPool1dParameter
avgpool1d_pb
=
layer_pb
.
avgpool1d
();
return
Load
(
avgpool1d_pb
);
return
true
;
}
bool
AvgPool1d
::
Load
(
const
AvgPool1dParameter
&
avgpool1d_pb
)
{
CHECK
(
avgpool1d_pb
.
has_kernel_size
());
CHECK_GT
(
avgpool1d_pb
.
has_kernel_size
(),
0
);
kernel_size_
=
avgpool1d_pb
.
kernel_size
();
if
(
avgpool1d_pb
.
has_stride
()
&&
avgpool1d_pb
.
stride
()
>
0
)
{
stride_
=
avgpool1d_pb
.
stride
();
}
else
{
ADEBUG
<<
"No valid stride found, use kernel size, instead"
;
stride_
=
avgpool1d_pb
.
kernel_size
();
}
return
true
;
}
void
AvgPool1d
::
Run
(
const
std
::
vector
<
Eigen
::
MatrixXf
>&
inputs
,
Eigen
::
MatrixXf
*
output
)
{
CHECK_EQ
(
inputs
.
size
(),
1
);
int
output_num_col
=
(
inputs
[
0
].
cols
()
-
kernel_size_
)
/
stride_
+
1
;
int
output_num_row
=
inputs
[
0
].
rows
();
output
->
resize
(
output_num_row
,
output_num_col
);
int
input_index
=
0
;
for
(
int
j
=
0
;
j
<
output_num_col
;
++
j
)
{
CHECK_LT
(
input_index
+
kernel_size_
,
inputs
[
0
].
cols
());
for
(
int
i
=
0
;
i
<
output_num_row
;
++
i
)
{
float
output_i_j_sum
=
0.0
;
for
(
int
k
=
input_index
;
k
<
input_index
+
kernel_size_
;
++
k
)
{
output_i_j_sum
+=
inputs
[
0
](
i
,
k
);
}
(
*
output
)(
i
,
j
)
=
output_i_j_sum
/
static_cast
<
float
>
(
kernel_size_
);
}
input_index
+=
stride_
;
}
}
bool
Activation
::
Load
(
const
LayerParameter
&
layer_pb
)
{
if
(
!
Layer
::
Load
(
layer_pb
))
{
AERROR
<<
"Fail to Load the layer parameters!"
;
...
...
modules/prediction/network/net_layer.h
浏览文件 @
9a1b5df0
...
...
@@ -146,12 +146,19 @@ class Dense : public Layer {
class
Conv1d
:
public
Layer
{
public:
/**
* @brief Load the
dense
layer parameter from a pb message
* @brief Load the layer parameter from a pb message
* @param A pb message contains the parameters
* @return True is loaded successively, otherwise False
*/
bool
Load
(
const
apollo
::
prediction
::
LayerParameter
&
layer_pb
)
override
;
/**
* @brief Load the conv1d layer parameter from a pb message
* @param A pb message contains the parameters
* @return True is loaded successively, otherwise False
*/
bool
Load
(
const
apollo
::
prediction
::
Conv1dParameter
&
conv1d_pb
);
/**
* @brief Compute the layer output from inputs
* @param Inputs to a network layer
...
...
@@ -175,12 +182,19 @@ class Conv1d : public Layer {
class
MaxPool1d
:
public
Layer
{
public:
/**
* @brief Load the
dense
layer parameter from a pb message
* @brief Load the layer parameter from a pb message
* @param A pb message contains the parameters
* @return True is loaded successively, otherwise False
*/
bool
Load
(
const
apollo
::
prediction
::
LayerParameter
&
layer_pb
)
override
;
/**
* @brief Load the max pool 1d layer parameter from a pb message
* @param A pb message contains the parameters
* @return True is loaded successively, otherwise False
*/
bool
Load
(
const
apollo
::
prediction
::
MaxPool1dParameter
&
maxpool1d_pb
);
/**
* @brief Compute the layer output from inputs
* @param Inputs to a network layer
...
...
@@ -191,6 +205,7 @@ class MaxPool1d : public Layer {
private:
int
kernel_size_
;
int
stride_
;
};
/**
...
...
@@ -206,6 +221,13 @@ class AvgPool1d : public Layer {
*/
bool
Load
(
const
apollo
::
prediction
::
LayerParameter
&
layer_pb
)
override
;
/**
* @brief Load the avg pool 1d layer parameter from a pb message
* @param A pb message contains the parameters
* @return True is loaded successively, otherwise False
*/
bool
Load
(
const
apollo
::
prediction
::
AvgPool1dParameter
&
avgpool1d_pb
);
/**
* @brief Compute the layer output from inputs
* @param Inputs to a network layer
...
...
@@ -216,6 +238,7 @@ class AvgPool1d : public Layer {
private:
int
kernel_size_
;
int
stride_
;
};
/**
...
...
modules/prediction/proto/cruise_model.proto
浏览文件 @
9a1b5df0
...
...
@@ -48,8 +48,8 @@ message Regress {
message
CruiseModel
{
optional
LaneFeatureConv
lane_feature_conv
=
1
;
optional
MaxPool1d
lane_feature_maxpool
=
2
;
optional
AvgPool1d
lane_feature_avgpool
=
3
;
optional
MaxPool1d
Parameter
lane_feature_maxpool
=
2
;
optional
AvgPool1d
Parameter
lane_feature_avgpool
=
3
;
optional
ObsFeatureFC
obs_feature_fc
=
5
;
optional
Classify
classify
=
6
;
optional
Regress
regress
=
7
;
...
...
modules/prediction/proto/network_layers.proto
浏览文件 @
9a1b5df0
...
...
@@ -29,12 +29,12 @@ message Conv1dParameter {
optional
int32
stride
=
5
;
}
message
MaxPool1d
{
message
MaxPool1d
Parameter
{
optional
int32
kernel_size
=
1
;
optional
int32
stride
=
2
;
}
message
AvgPool1d
{
message
AvgPool1d
Parameter
{
optional
int32
kernel_size
=
1
;
optional
int32
stride
=
2
;
}
...
...
@@ -102,7 +102,7 @@ message LayerParameter {
FlattenParameter
flatten
=
9
;
ConcatenateParameter
concatenate
=
10
;
Conv1dParameter
conv1d
=
11
;
MaxPool1d
maxpool1d
=
12
;
AvgPool1d
avgpool1d
=
13
;
MaxPool1d
Parameter
maxpool1d
=
12
;
AvgPool1d
Parameter
avgpool1d
=
13
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录