Apollo  6.0
Open source self driving car software
net_model.h
Go to the documentation of this file.
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 
17 #pragma once
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
24 #include "modules/prediction/proto/network_model.pb.h"
25 
30 namespace apollo {
31 namespace prediction {
32 namespace network {
33 
40 class NetModel {
41  public:
45  NetModel() = default;
46 
50  virtual ~NetModel() = default;
51 
57  virtual void Run(const std::vector<Eigen::MatrixXf>& inputs,
58  Eigen::MatrixXf* output) const = 0;
59 
64  virtual void SetState(const std::vector<Eigen::MatrixXf>& states) {}
65 
70  virtual void State(std::vector<Eigen::MatrixXf>* states) const {}
71 
76  virtual void ResetState() const {}
77 
83  bool LoadModel(const NetParameter& net_parameter);
84 
89  std::string PerformanceString() const;
90 
95  const std::string& Name() const;
96 
101  int Id() const;
102 
107  bool IsOk() const;
108 
109  protected:
110  std::vector<std::unique_ptr<Layer>> layers_;
111  NetParameter net_parameter_;
112  bool ok_ = false;
113 };
114 
115 } // namespace network
116 } // namespace prediction
117 } // namespace apollo
std::vector< std::unique_ptr< Layer > > layers_
Definition: net_model.h:110
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool ok_
Definition: net_model.h:112
NetParameter net_parameter_
Definition: net_model.h:111
int Id() const
Id of a network model.
bool LoadModel(const NetParameter &net_parameter)
Load network parameters from a protobuf message.
virtual void SetState(const std::vector< Eigen::MatrixXf > &states)
Set the internal state of a network model.
Definition: net_model.h:64
std::string PerformanceString() const
Shows the performance information of a network.
const std::string & Name() const
Name of a network model.
bool IsOk() const
Indicate the state of a network model.
NetModel is a base class for specific network model It contains a pure virtual function Run which mus...
Definition: net_model.h:40
virtual void ResetState() const
Set the internal state of a model.
Definition: net_model.h:76
virtual void State(std::vector< Eigen::MatrixXf > *states) const
Access to the internal state of a network model.
Definition: net_model.h:70
virtual void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) const =0
Compute the model output from inputs.
virtual ~NetModel()=default
Destructor.