Apollo 11.0
自动驾驶开放平台
rnn_model.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19namespace apollo {
20namespace prediction {
21namespace network {
22
23RnnModel::RnnModel() {}
24
25void RnnModel::Run(const std::vector<Eigen::MatrixXf>& inputs,
26 Eigen::MatrixXf* output) const {
27 Eigen::MatrixXf inp1;
28 Eigen::MatrixXf inp2;
29 layers_[0]->Run({inputs[0]}, &inp1);
30 layers_[1]->Run({inputs[1]}, &inp2);
31
32 Eigen::MatrixXf bn1;
33 Eigen::MatrixXf bn2;
34 layers_[2]->Run({inp1}, &bn1);
35 layers_[3]->Run({inp2}, &bn2);
36
37 Eigen::MatrixXf lstm1;
38 Eigen::MatrixXf lstm2;
39 layers_[4]->Run({bn1}, &lstm1);
40 layers_[5]->Run({bn2}, &lstm2);
41
42 Eigen::MatrixXf merge;
43 Eigen::MatrixXf dense1;
44 Eigen::MatrixXf act1;
45 layers_[6]->Run({lstm1, lstm2}, &merge);
46 layers_[7]->Run({merge}, &dense1);
47 layers_[8]->Run({dense1}, &bn1);
48 layers_[9]->Run({bn1}, &act1);
49
50 Eigen::MatrixXf dense2;
51 Eigen::MatrixXf prob;
52 layers_[10]->Run({act1}, &dense2);
53 layers_[12]->Run({dense2}, &bn1);
54 layers_[14]->Run({bn1}, &prob);
55
56 Eigen::MatrixXf acc;
57 layers_[11]->Run({act1}, &dense2);
58 layers_[13]->Run({dense2}, &bn1);
59 layers_[15]->Run({bn1}, &acc);
60
61 output->resize(1, 2);
62 *output << prob, acc;
63}
64
65void RnnModel::SetState(const std::vector<Eigen::MatrixXf>& states) {
66 layers_[4]->SetState(states);
67 layers_[5]->ResetState();
68}
69
70void RnnModel::State(std::vector<Eigen::MatrixXf>* states) const {
71 layers_[4]->State(states);
72}
73
75 layers_[4]->ResetState();
76 layers_[5]->ResetState();
77}
78
79} // namespace network
80} // namespace prediction
81} // namespace apollo
std::vector< std::unique_ptr< Layer > > layers_
Definition net_model.h:110
void State(std::vector< Eigen::MatrixXf > *states) const override
Access to the internal state of a network model
Definition rnn_model.cc:70
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) const override
Compute the model output from inputs according to a defined layers' flow
Definition rnn_model.cc:25
void ResetState() const override
Set the internal state of a model
Definition rnn_model.cc:74
void SetState(const std::vector< Eigen::MatrixXf > &states) override
Set the internal state of a network model
Definition rnn_model.cc:65
class register implement
Definition arena_queue.h:37