Apollo 11.0
自动驾驶开放平台
apollo::prediction::network::NetModel类 参考abstract

NetModel is a base class for specific network model It contains a pure virtual function Run which must be implemented in derived class 更多...

#include <net_model.h>

类 apollo::prediction::network::NetModel 继承关系图:
apollo::prediction::network::NetModel 的协作图:

Public 成员函数

 NetModel ()=default
 Constructor
 
virtual ~NetModel ()=default
 Destructor
 
virtual void Run (const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) const =0
 Compute the model output from inputs
 
virtual void SetState (const std::vector< Eigen::MatrixXf > &states)
 Set the internal state of a network model
 
virtual void State (std::vector< Eigen::MatrixXf > *states) const
 Access to the internal state of a network model
 
virtual void ResetState () const
 Set the internal state of a model
 
bool LoadModel (const NetParameter &net_parameter)
 Load network parameters from a protobuf message
 
std::string PerformanceString () const
 Shows the performance information of a network
 
const std::string & Name () const
 Name of a network model
 
int Id () const
 Id of a network model
 
bool IsOk () const
 Indicate the state of a network model
 

Protected 属性

std::vector< std::unique_ptr< Layer > > layers_
 
NetParameter net_parameter_
 
bool ok_ = false
 

详细描述

NetModel is a base class for specific network model It contains a pure virtual function Run which must be implemented in derived class

在文件 net_model.h40 行定义.

构造及析构函数说明

◆ NetModel()

apollo::prediction::network::NetModel::NetModel ( )
default

Constructor

◆ ~NetModel()

virtual apollo::prediction::network::NetModel::~NetModel ( )
virtualdefault

Destructor

成员函数说明

◆ Id()

int apollo::prediction::network::NetModel::Id ( ) const

Id of a network model

返回
Id of a network model

在文件 net_model.cc97 行定义.

◆ IsOk()

bool apollo::prediction::network::NetModel::IsOk ( ) const

Indicate the state of a network model

返回
True of a network model is load successively, otherwise False.

在文件 net_model.cc99 行定义.

◆ LoadModel()

bool apollo::prediction::network::NetModel::LoadModel ( const NetParameter net_parameter)

Load network parameters from a protobuf message

参数
NetParameteris a protobuf message
返回
True if successfully loaded, otherwise False

在文件 net_model.cc27 行定义.

27 {
28 net_parameter_.CopyFrom(net_parameter);
29 layers_.clear();
30
31 for (int i = 0; i < net_parameter_.layers_size(); ++i) {
32 LayerParameter layer_pb = net_parameter_.layers(i);
33 ADEBUG << i << "-th layer name: " << layer_pb.name().c_str();
34 std::unique_ptr<Layer> layer(nullptr);
35 switch (layer_pb.oneof_layers_case()) {
36 case LayerParameter::kInput:
37 layer = std::unique_ptr<Layer>(new Input());
38 break;
39 case LayerParameter::kActivation:
40 layer = std::unique_ptr<Layer>(new Activation());
41 break;
42 case LayerParameter::kDense:
43 layer = std::unique_ptr<Layer>(new Dense());
44 break;
45 case LayerParameter::kBatchNormalization:
46 layer = std::unique_ptr<Layer>(new BatchNormalization());
47 break;
48 case LayerParameter::kLstm:
49 layer = std::unique_ptr<Layer>(new LSTM());
50 break;
51 case LayerParameter::kFlatten:
52 layer = std::unique_ptr<Layer>(new Flatten());
53 break;
54 case LayerParameter::kConcatenate:
55 layer = std::unique_ptr<Layer>(new Concatenate());
56 break;
57 default:
58 AERROR << "Failed to load layer: " << layer_pb.type().c_str();
59 break;
60 }
61 if (!layer->Load(layer_pb)) {
62 AERROR << "Failed to load " << i << "-layer: " << layer_pb.name().c_str();
63 return false;
64 }
65 layers_.push_back(std::move(layer));
66 }
67 ok_ = true;
68 AINFO << "Success in loading the model!";
69 ADEBUG << "Its Performance:" << PerformanceString().c_str();
70 return true;
71}
std::string PerformanceString() const
Shows the performance information of a network
Definition net_model.cc:73
std::vector< std::unique_ptr< Layer > > layers_
Definition net_model.h:110
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

◆ Name()

const std::string & apollo::prediction::network::NetModel::Name ( ) const

Name of a network model

返回
Name of a network model

在文件 net_model.cc95 行定义.

◆ PerformanceString()

std::string apollo::prediction::network::NetModel::PerformanceString ( ) const

Shows the performance information of a network

返回
Performance of a network model

在文件 net_model.cc73 行定义.

73 {
74 std::stringstream ss;
75 if (!net_parameter_.has_performance()) {
76 AWARN << "The protobuf does not contain performance values!";
77 return " ";
78 }
79 ss << "\n test: accuracy = ";
80 for (int i = 0; i < net_parameter_.performance().accuracy_size(); ++i) {
81 ss << net_parameter_.performance().accuracy(i) << ", ";
82 }
83 ss << "\n recall = ";
84 for (int i = 0; i < net_parameter_.performance().recall_size(); ++i) {
85 ss << net_parameter_.performance().recall(i) << ", ";
86 }
87 ss << "\n precision = ";
88 for (int i = 0; i < net_parameter_.performance().precision_size(); ++i) {
89 ss << net_parameter_.performance().precision(i) << ", ";
90 }
91 ss << std::endl;
92 return ss.str();
93}
#define AWARN
Definition log.h:43

◆ ResetState()

virtual void apollo::prediction::network::NetModel::ResetState ( ) const
inlinevirtual

Set the internal state of a model

参数
Aspecified internal state in a vector of Eigen::MatrixXf

apollo::prediction::network::RnnModel 重载.

在文件 net_model.h76 行定义.

76{}

◆ Run()

virtual void apollo::prediction::network::NetModel::Run ( const std::vector< Eigen::MatrixXf > &  inputs,
Eigen::MatrixXf *  output 
) const
pure virtual

Compute the model output from inputs

参数
Inputsto a network
Outputof a network will be returned

apollo::planning::AutotuningMLPModel , 以及 apollo::prediction::network::RnnModel 内被实现.

◆ SetState()

virtual void apollo::prediction::network::NetModel::SetState ( const std::vector< Eigen::MatrixXf > &  states)
inlinevirtual

Set the internal state of a network model

参数
Aspecified internal state in a vector of Eigen::MatrixXf

apollo::prediction::network::RnnModel 重载.

在文件 net_model.h64 行定义.

64{}

◆ State()

virtual void apollo::prediction::network::NetModel::State ( std::vector< Eigen::MatrixXf > *  states) const
inlinevirtual

Access to the internal state of a network model

返回
Internal state in a vector of Eigen::MatrixXf of the model

apollo::prediction::network::RnnModel 重载.

在文件 net_model.h70 行定义.

70{}

类成员变量说明

◆ layers_

std::vector<std::unique_ptr<Layer> > apollo::prediction::network::NetModel::layers_
protected

在文件 net_model.h110 行定义.

◆ net_parameter_

NetParameter apollo::prediction::network::NetModel::net_parameter_
protected

在文件 net_model.h111 行定义.

◆ ok_

bool apollo::prediction::network::NetModel::ok_ = false
protected

在文件 net_model.h112 行定义.


该类的文档由以下文件生成: