Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
3b35cb85
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,发现更多精彩内容 >>
提交
3b35cb85
编写于
7月 20, 2017
作者:
K
kechxu
提交者:
Calvin Miao
7月 20, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement computing probabilites for mlp model
上级
eb4fd44e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
151 addition
and
3 deletion
+151
-3
modules/prediction/common/BUILD
modules/prediction/common/BUILD
+7
-0
modules/prediction/common/prediction_util.cc
modules/prediction/common/prediction_util.cc
+40
-0
modules/prediction/common/prediction_util.h
modules/prediction/common/prediction_util.h
+34
-0
modules/prediction/evaluator/vehicle/BUILD
modules/prediction/evaluator/vehicle/BUILD
+1
-0
modules/prediction/evaluator/vehicle/mlp_evaluator.cc
modules/prediction/evaluator/vehicle/mlp_evaluator.cc
+69
-3
未找到文件。
modules/prediction/common/BUILD
浏览文件 @
3b35cb85
...
...
@@ -12,4 +12,11 @@ cc_library(
],
)
cc_library
(
name
=
"prediction_util"
,
srcs
=
[
"prediction_util.cc"
],
hdrs
=
[
"prediction_util.h"
],
deps
=
[],
)
cpplint
()
modules/prediction/common/prediction_util.cc
0 → 100644
浏览文件 @
3b35cb85
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include <cmath>
#include "modules/prediction/common/prediction_util.h"
namespace
apollo
{
namespace
prediction
{
namespace
util
{
double
Normalize
(
const
double
value
,
const
double
mean
,
const
double
std
)
{
double
eps
=
1e-10
;
return
(
value
-
mean
)
/
(
std
+
eps
);
}
double
Sigmoid
(
const
double
value
)
{
return
1
/
(
1
+
std
::
exp
(
-
1.0
*
value
));
}
double
Relu
(
const
double
value
)
{
return
(
value
>
0.0
)
?
value
:
0.0
;
}
}
// namespace util
}
// namespace prediction
}
// namespace apollo
modules/prediction/common/prediction_util.h
0 → 100644
浏览文件 @
3b35cb85
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef MODULES_PREDICTION_COMMON_PREDICTION_UTIL_H_
#define MODULES_PREDICTION_COMMON_PREDICTION_UTIL_H_
namespace
apollo
{
namespace
prediction
{
namespace
util
{
double
Normalize
(
const
double
value
,
const
double
mean
,
const
double
std
);
double
Sigmoid
(
const
double
value
);
double
Relu
(
const
double
value
);
}
// namespace util
}
// namespace prediction
}
// namespace apollo
#endif // MODULES_PREDICTION_COMMON_PREDICTION_UTIL_H_
modules/prediction/evaluator/vehicle/BUILD
浏览文件 @
3b35cb85
...
...
@@ -17,6 +17,7 @@ cc_library(
"//modules/prediction/common:prediction_common"
,
"//modules/common/math:math_utils"
,
"//modules/prediction/proto:fnn_vehicle_model_proto"
,
"//modules/prediction/common:prediction_util"
,
],
)
...
...
modules/prediction/evaluator/vehicle/mlp_evaluator.cc
浏览文件 @
3b35cb85
...
...
@@ -15,10 +15,12 @@
*****************************************************************************/
#include <cmath>
#include <fstream>
#include "modules/prediction/evaluator/vehicle/mlp_evaluator.h"
#include "modules/prediction/common/prediction_gflags.h"
#include "modules/common/math/math_utils.h"
#include "modules/prediction/common/prediction_util.h"
namespace
apollo
{
namespace
prediction
{
...
...
@@ -254,12 +256,76 @@ void MLPEvaluator::SetLaneFeatureValues(Obstacle* obstacle_ptr,
}
void
MLPEvaluator
::
LoadModel
(
const
std
::
string
&
model_file
)
{
// TODO(kechxu) implement
model_ptr_
.
reset
(
new
FnnVehicleModel
());
CHECK
(
model_ptr_
!=
nullptr
);
std
::
fstream
file_stream
(
model_file
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
if
(
!
file_stream
.
good
())
{
AERROR
<<
"Unable to open the model file: "
<<
model_file
<<
"."
;
return
;
}
if
(
!
model_ptr_
->
ParseFromIstream
(
&
file_stream
))
{
AERROR
<<
"Unable to load the model file: "
<<
model_file
<<
"."
;
return
;
}
ADEBUG
<<
"Succeeded in loading the model file: "
<<
model_file
<<
"."
;
}
double
MLPEvaluator
::
ComputeProbability
()
{
// TODO(kechxu) implement
return
0.0
;
CHECK
(
model_ptr_
.
get
()
!=
nullptr
);
double
probability
=
0.0
;
if
(
model_ptr_
->
dim_input
()
!=
static_cast
<
int
>
(
feature_values_
.
size
()))
{
AERROR
<<
"Model feature size not consistent with model proto definition."
;
return
probability
;
}
std
::
vector
<
double
>
layer_input
;
layer_input
.
reserve
(
model_ptr_
->
dim_input
());
std
::
vector
<
double
>
layer_output
;
// normalization
for
(
int
i
=
0
;
i
<
model_ptr_
->
dim_input
();
++
i
)
{
double
mean
=
model_ptr_
->
samples_mean
().
columns
(
i
);
double
std
=
model_ptr_
->
samples_std
().
columns
(
i
);
layer_input
.
push_back
(
apollo
::
prediction
::
util
::
Normalize
(
feature_values_
[
i
],
mean
,
std
));
}
for
(
int
i
=
0
;
i
<
model_ptr_
->
num_layer
();
++
i
)
{
if
(
i
>
0
)
{
layer_input
.
clear
();
layer_output
.
swap
(
layer_output
);
}
const
Layer
&
layer
=
model_ptr_
->
layer
(
i
);
for
(
int
col
=
0
;
col
<
layer
.
layer_output_dim
();
++
col
)
{
double
neuron_output
=
layer
.
layer_bias
().
columns
(
col
);
for
(
int
row
=
0
;
row
<
layer
.
layer_input_dim
();
++
row
)
{
double
weight
=
layer
.
layer_input_weight
().
rows
(
row
).
columns
(
col
);
neuron_output
+=
(
layer_input
[
row
]
*
weight
);
}
if
(
layer
.
layer_activation_type
()
==
"relu"
)
{
neuron_output
=
apollo
::
prediction
::
util
::
Relu
(
neuron_output
);
}
else
if
(
layer
.
layer_activation_type
()
==
"sigmoid"
)
{
neuron_output
=
apollo
::
prediction
::
util
::
Sigmoid
(
neuron_output
);
}
else
if
(
layer
.
layer_activation_type
()
==
"tanh"
)
{
neuron_output
=
std
::
tanh
(
neuron_output
);
}
else
{
LOG
(
ERROR
)
<<
"Undefined activation func: "
<<
layer
.
layer_activation_type
()
<<
", and default sigmoid will be used instead."
;
neuron_output
=
apollo
::
prediction
::
util
::
Sigmoid
(
neuron_output
);
}
layer_output
.
push_back
(
neuron_output
);
}
}
if
(
layer_output
.
size
()
!=
1
)
{
AERROR
<<
"Model output layer has incorrect # outputs: "
<<
layer_output
.
size
();
}
else
{
probability
=
layer_output
[
0
];
}
return
probability
;
}
}
// namespace prediction
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录