Apollo 10.0
自动驾驶开放平台
apollo::prediction::network 命名空间参考

apollo::prediction::network 更多...

class  Activation
 Activation is an activation network layer. 更多...
 
class  AvgPool1d
 AvgPool1d is the average Pool 1d network layer. 更多...
 
class  BatchNormalization
 
class  Concatenate
 concatenates a vector of inputs, return a single matrix. 更多...
 
class  Conv1d
 Conv1d is the convolution 1d network layer. 更多...
 
class  Dense
 Dense is the forward fully connected network layer. 更多...
 
class  Flatten
 network layer to flatten a matrix into vector. 更多...
 
class  Input
 the input layer for a network, which specified the shape of input matrix 更多...
 
class  Layer
 Layer is a base class for specific network layers It contains a pure virtual function Run which must be implemented in derived class 更多...
 
class  LSTM
 Long-Short Term Memory unit - Hochreiter 1997. 更多...
 
class  MaxPool1d
 MaxPool1d is the max Pool 1d network layer. 更多...
 
class  NetModel
 NetModel is a base class for specific network model It contains a pure virtual function Run which must be implemented in derived class 更多...
 
class  RnnModel
 RnnModel is a derived class from NetModel, it has a specific layers structure. 更多...
 

函数

float sigmoid (const float x)
 sigmoid function: f(x) = 1 / (1 + exp(-x))
 
float tanh (const float x)
 hyperbolic tangent function: f(x) = (1 + exp(-2x)) / (1 - exp(-2x))
 
float linear (const float x)
 linear function: f(x) = x
 
float hard_sigmoid (const float x)
 "hard" sigmoid function: | 0.0 x in (-oo, 0) f(x) = | 0.2x + 0.5 x in [0, 2.5] | 1.0 x in (2.5, +oo)
 
float relu (const float x)
 relu function: | 0.0 x in (-oo, 0.0) f(x) = | | x x in [0.0, +oo)
 
Eigen::MatrixXf FlattenMatrix (const Eigen::MatrixXf &matrix)
 flatten a matrix to a row vector
 
std::function< float(float)> serialize_to_function (const std::string &str)
 translate a string into a network activation function
 
bool LoadTensor (const TensorParameter &tensor_pb, Eigen::MatrixXf *matrix)
 load matrix value from a protobuf message
 
bool LoadTensor (const TensorParameter &tensor_pb, Eigen::VectorXf *vector)
 load vector value from a protobuf message
 
bool LoadTensor (const TensorParameter &tensor_pb, std::vector< Eigen::MatrixXf > *const tensor3d)
 load matrix value from a protobuf message
 

详细描述

函数说明

◆ FlattenMatrix()

Eigen::MatrixXf apollo::prediction::network::FlattenMatrix ( const Eigen::MatrixXf &  matrix)

flatten a matrix to a row vector

参数
Inputmatrix
返回
Flattened matrix

在文件 net_util.cc40 行定义.

40 {
41 CHECK_GT(matrix.rows(), 0);
42 CHECK_GT(matrix.cols(), 0);
43 int output_size = static_cast<int>(matrix.rows() * matrix.cols());
44 Eigen::MatrixXf output_matrix;
45 output_matrix.resize(1, output_size);
46 int output_index = 0;
47 for (int i = 0; i < matrix.rows(); ++i) {
48 for (int j = 0; j < matrix.cols(); ++j) {
49 output_matrix(0, output_index) = matrix(i, j);
50 ++output_index;
51 }
52 }
53 return output_matrix;
54}

◆ hard_sigmoid()

float apollo::prediction::network::hard_sigmoid ( const float  x)

"hard" sigmoid function: | 0.0 x in (-oo, 0) f(x) = | 0.2x + 0.5 x in [0, 2.5] | 1.0 x in (2.5, +oo)

在文件 net_util.cc33 行定义.

33 {
34 const float z = 0.2f * x + 0.5f;
35 return z <= 0.0f ? 0.0f : (z <= 1.0f ? z : 1.0f);
36}

◆ linear()

float apollo::prediction::network::linear ( const float  x)

linear function: f(x) = x

在文件 net_util.cc31 行定义.

31{ return x; }

◆ LoadTensor() [1/3]

bool apollo::prediction::network::LoadTensor ( const TensorParameter tensor_pb,
Eigen::MatrixXf *  matrix 
)

load matrix value from a protobuf message

参数
protobufmessage in the form of TensorParameter
Eigen::MatrixXfwill be returned
返回
True if load data successively, otherwise False

在文件 net_util.cc66 行定义.

66 {
67 if (tensor_pb.data().empty() || tensor_pb.shape().empty()) {
68 AERROR << "Fail to load the necessary fields!";
69 return false;
70 }
71 if (tensor_pb.shape_size() < 2) {
72 ADEBUG << "Load tensor size: (1, " << tensor_pb.shape(0) << ")";
73 matrix->resize(1, tensor_pb.shape(0));
74 for (int i = 0; i < tensor_pb.shape(0); ++i) {
75 (*matrix)(0, i) = static_cast<float>(tensor_pb.data(i));
76 }
77 return true;
78 }
79 ADEBUG << "Load tensor size: (" << tensor_pb.shape(0) << ", "
80 << tensor_pb.shape(1) << ")";
81 CHECK_EQ(tensor_pb.shape_size(), 2);
82 matrix->resize(tensor_pb.shape(0), tensor_pb.shape(1));
83 for (int i = 0; i < tensor_pb.shape(0); ++i) {
84 for (int j = 0; j < tensor_pb.shape(1); ++j) {
85 (*matrix)(i, j) =
86 static_cast<float>(tensor_pb.data(i * tensor_pb.shape(1) + j));
87 }
88 }
89 return true;
90}
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
repeated float data
repeated int32 shape

◆ LoadTensor() [2/3]

bool apollo::prediction::network::LoadTensor ( const TensorParameter tensor_pb,
Eigen::VectorXf *  vector 
)

load vector value from a protobuf message

参数
protobufmessage in the form of TensorParameter
Eigen::VectorXfwill be returned
返回
True if load data successively, otherwise False

在文件 net_util.cc92 行定义.

92 {
93 if (tensor_pb.data().empty() || tensor_pb.shape().empty()) {
94 AERROR << "Fail to load the necessary fields!";
95 return false;
96 }
97 ADEBUG << "Load tensor size: (" << tensor_pb.shape(0) << ", 1)";
98 CHECK_EQ(tensor_pb.shape_size(), 1);
99 if (tensor_pb.shape_size() == 1) {
100 vector->resize(tensor_pb.shape(0));
101 for (int i = 0; i < tensor_pb.shape(0); ++i) {
102 (*vector)(i) = static_cast<float>(tensor_pb.data(i));
103 }
104 }
105 return true;
106}

◆ LoadTensor() [3/3]

bool apollo::prediction::network::LoadTensor ( const TensorParameter tensor_pb,
std::vector< Eigen::MatrixXf > *const  tensor3d 
)

load matrix value from a protobuf message

参数
protobufmessage in the form of TensorParameter
vectorof Eigen::MatrixXf will be returned
返回
True if load data successively, otherwise False

在文件 net_util.cc108 行定义.

109 {
110 if (tensor_pb.data().empty() || tensor_pb.shape_size() != 3) {
111 AERROR << "Fail to load the necessary fields!";
112 return false;
113 }
114 int num_depth = tensor_pb.shape(0);
115 int num_row = tensor_pb.shape(1);
116 int num_col = tensor_pb.shape(2);
117 CHECK_EQ(tensor_pb.data_size(), num_depth * num_row * num_col);
118 int tensor_pb_index = 0;
119 for (int k = 0; k < num_depth; ++k) {
120 Eigen::MatrixXf matrix = Eigen::MatrixXf::Zero(num_row, num_col);
121 for (int i = 0; i < num_row; ++i) {
122 for (int j = 0; j < num_col; ++j) {
123 matrix(i, j) = tensor_pb.data(tensor_pb_index);
124 ++tensor_pb_index;
125 }
126 }
127 tensor3d->push_back(matrix);
128 }
129 CHECK_EQ(tensor_pb_index, num_depth * num_row * num_col);
130 return true;
131}

◆ relu()

float apollo::prediction::network::relu ( const float  x)

relu function: | 0.0 x in (-oo, 0.0) f(x) = | | x x in [0.0, +oo)

在文件 net_util.cc38 行定义.

38{ return (x > 0.0f) ? x : 0.0f; }

◆ serialize_to_function()

std::function< float(float)> apollo::prediction::network::serialize_to_function ( const std::string &  str)

translate a string into a network activation function

参数
string
返回
activation function map to the string

在文件 net_util.cc56 行定义.

56 {
57 static const std::unordered_map<std::string, std::function<float(float)>>
58 func_map({{"linear", linear},
59 {"tanh", tanh},
60 {"sigmoid", sigmoid},
61 {"hard_sigmoid", hard_sigmoid},
62 {"relu", relu}});
63 return func_map.at(str);
64}
float linear(const float x)
linear function: f(x) = x
Definition net_util.cc:31
float relu(const float x)
relu function: | 0.0 x in (-oo, 0.0) f(x) = | | x x in [0.0, +oo)
Definition net_util.cc:38

◆ sigmoid()

float apollo::prediction::network::sigmoid ( const float  x)

sigmoid function: f(x) = 1 / (1 + exp(-x))

在文件 net_util.cc27 行定义.

27{ return 1.0f / (1.0f + std::exp(-x)); }

◆ tanh()

float apollo::prediction::network::tanh ( const float  x)

hyperbolic tangent function: f(x) = (1 + exp(-2x)) / (1 - exp(-2x))

在文件 net_util.cc29 行定义.

29{ return std::tanh(x); }