Apollo 11.0
自动驾驶开放平台
net_layer.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
22
23#include <algorithm>
24#include <limits>
25
26#include "cyber/common/log.h"
27
28namespace apollo {
29namespace prediction {
30namespace network {
31
32bool Layer::Load(const LayerParameter& layer_pb) {
33 if (!layer_pb.has_name()) {
34 ADEBUG << "Set name at default";
35 name_ = "layer";
36 } else {
37 name_ = layer_pb.name();
38 }
39 if (!layer_pb.has_order_number()) {
40 ADEBUG << "Set order number at default";
41 order_number_ = -1;
42 } else {
43 order_number_ = layer_pb.order_number();
44 }
45 return true;
46}
47
48bool Dense::Load(const LayerParameter& layer_pb) {
49 if (!Layer::Load(layer_pb)) {
50 AERROR << "Fail to Load LayerParameter!";
51 return false;
52 }
53 DenseParameter dense_pb = layer_pb.dense();
54 return Load(dense_pb);
55}
56
57bool Dense::Load(const DenseParameter& dense_pb) {
58 if (!dense_pb.has_weights() || !LoadTensor(dense_pb.weights(), &weights_)) {
59 AERROR << "Fail to Load weights!";
60 return false;
61 }
62 if (!dense_pb.has_bias() || !LoadTensor(dense_pb.bias(), &bias_)) {
63 AERROR << "Fail to Load bias!";
64 return false;
65 }
66 if (!dense_pb.has_use_bias()) {
67 AWARN << "Set use_bias as false.";
68 use_bias_ = true;
69 } else {
70 use_bias_ = dense_pb.use_bias();
71 }
72 if (!dense_pb.has_activation()) {
73 ADEBUG << "Set activation as linear function";
74 kactivation_ = serialize_to_function("linear");
75 } else {
76 kactivation_ = serialize_to_function(dense_pb.activation());
77 }
78 units_ = dense_pb.units();
79 return true;
80}
81
82void Dense::Run(const std::vector<Eigen::MatrixXf>& inputs,
83 Eigen::MatrixXf* output) {
84 CHECK_EQ(inputs.size(), 1U);
85 Eigen::MatrixXf prod = static_cast<Eigen::MatrixXf>(inputs[0] * weights_);
86 if (use_bias_) {
87 Eigen::MatrixXf sum = prod.rowwise() + bias_.transpose();
88 prod = sum;
89 }
90 *output = prod.unaryExpr(kactivation_);
91 CHECK_EQ(output->cols(), units_);
92}
93
94bool Conv1d::Load(const LayerParameter& layer_pb) {
95 if (!Layer::Load(layer_pb)) {
96 AERROR << "Fail to Load LayerParameter!";
97 return false;
98 }
99 Conv1dParameter conv1d_pb = layer_pb.conv1d();
100 return Load(conv1d_pb);
101}
102
103bool Conv1d::Load(const Conv1dParameter& conv1d_pb) {
104 if (!conv1d_pb.has_kernel() || !LoadTensor(conv1d_pb.kernel(), &kernel_)) {
105 AERROR << "Fail to Load kernel!";
106 return false;
107 }
108 if (!conv1d_pb.has_bias() || !LoadTensor(conv1d_pb.bias(), &bias_)) {
109 AERROR << "Fail to Load bias!";
110 return false;
111 }
112 if (!conv1d_pb.has_use_bias()) {
113 AWARN << "Set use_bias as false.";
114 use_bias_ = true;
115 } else {
116 use_bias_ = conv1d_pb.use_bias();
117 }
118 for (int sz : conv1d_pb.shape()) {
119 shape_.push_back(sz);
120 }
121 if (conv1d_pb.has_stride()) {
122 stride_ = conv1d_pb.stride();
123 } else {
124 stride_ = 1;
125 }
126 return true;
127}
128
129void Conv1d::Run(const std::vector<Eigen::MatrixXf>& inputs,
130 Eigen::MatrixXf* output) {
131 CHECK_EQ(inputs.size(), 1U);
132 CHECK_GT(kernel_.size(), 0U);
133 CHECK_EQ(kernel_[0].rows(), inputs[0].rows());
134 int kernel_size = static_cast<int>(kernel_[0].cols());
135 int output_num_col =
136 static_cast<int>((inputs[0].cols() - kernel_size) / stride_) + 1;
137 int output_num_row = static_cast<int>(kernel_.size());
138 output->resize(output_num_row, output_num_col);
139 for (int i = 0; i < output_num_row; ++i) {
140 for (int j = 0; j < output_num_col; ++j) {
141 float output_i_j_unbiased = 0.0f;
142 for (int p = 0; p < inputs[0].rows(); ++p) {
143 for (int q = j * stride_; q < j * stride_ + kernel_size; ++q) {
144 output_i_j_unbiased +=
145 inputs[0](p, q) * kernel_[i](p, q - j * stride_);
146 }
147 }
148
149 (*output)(i, j) = output_i_j_unbiased + bias_(i);
150 }
151 }
152}
153
154bool MaxPool1d::Load(const LayerParameter& layer_pb) {
155 if (!Layer::Load(layer_pb)) {
156 AERROR << "Fail to Load LayerParameter!";
157 return false;
158 }
159 MaxPool1dParameter maxpool1d_pb = layer_pb.maxpool1d();
160 return Load(maxpool1d_pb);
161}
162
163bool MaxPool1d::Load(const MaxPool1dParameter& maxpool1d_pb) {
164 ACHECK(maxpool1d_pb.has_kernel_size());
165 CHECK_GT(maxpool1d_pb.has_kernel_size(), 0);
166 kernel_size_ = maxpool1d_pb.kernel_size();
167 if (maxpool1d_pb.has_stride() && maxpool1d_pb.stride() > 0) {
168 stride_ = maxpool1d_pb.stride();
169 } else {
170 ADEBUG << "No valid stride found, use kernel size, instead";
171 stride_ = maxpool1d_pb.kernel_size();
172 }
173 return true;
174}
175
176void MaxPool1d::Run(const std::vector<Eigen::MatrixXf>& inputs,
177 Eigen::MatrixXf* output) {
178 CHECK_EQ(inputs.size(), 1U);
179 int output_num_col =
180 static_cast<int>((inputs[0].cols() - kernel_size_) / stride_) + 1;
181 int output_num_row = static_cast<int>(inputs[0].rows());
182 output->resize(output_num_row, output_num_col);
183 int input_index = 0;
184 for (int j = 0; j < output_num_col; ++j) {
185 CHECK_LE(input_index + kernel_size_, inputs[0].cols());
186 for (int i = 0; i < output_num_row; ++i) {
187 float output_i_j = -std::numeric_limits<float>::infinity();
188 for (int k = input_index; k < input_index + kernel_size_; ++k) {
189 output_i_j = std::max(output_i_j, inputs[0](i, k));
190 }
191 (*output)(i, j) = output_i_j;
192 }
193 input_index += stride_;
194 }
195}
196
197bool AvgPool1d::Load(const LayerParameter& layer_pb) {
198 if (!Layer::Load(layer_pb)) {
199 AERROR << "Fail to Load LayerParameter!";
200 return false;
201 }
202 AvgPool1dParameter avgpool1d_pb = layer_pb.avgpool1d();
203 return Load(avgpool1d_pb);
204}
205
206bool AvgPool1d::Load(const AvgPool1dParameter& avgpool1d_pb) {
207 ACHECK(avgpool1d_pb.has_kernel_size());
208 CHECK_GT(avgpool1d_pb.has_kernel_size(), 0);
209 kernel_size_ = avgpool1d_pb.kernel_size();
210 if (avgpool1d_pb.has_stride() && avgpool1d_pb.stride() > 0) {
211 stride_ = avgpool1d_pb.stride();
212 } else {
213 ADEBUG << "No valid stride found, use kernel size, instead";
214 stride_ = avgpool1d_pb.kernel_size();
215 }
216 return true;
217}
218
219void AvgPool1d::Run(const std::vector<Eigen::MatrixXf>& inputs,
220 Eigen::MatrixXf* output) {
221 CHECK_EQ(inputs.size(), 1U);
222 int output_num_col =
223 static_cast<int>((inputs[0].cols() - kernel_size_) / stride_) + 1;
224 int output_num_row = static_cast<int>(inputs[0].rows());
225 output->resize(output_num_row, output_num_col);
226 int input_index = 0;
227 for (int j = 0; j < output_num_col; ++j) {
228 CHECK_LE(input_index + kernel_size_, inputs[0].cols());
229 for (int i = 0; i < output_num_row; ++i) {
230 float output_i_j_sum = 0.0f;
231 for (int k = input_index; k < input_index + kernel_size_; ++k) {
232 output_i_j_sum += inputs[0](i, k);
233 }
234 (*output)(i, j) = output_i_j_sum / static_cast<float>(kernel_size_);
235 }
236 input_index += stride_;
237 }
238}
239
240bool Activation::Load(const LayerParameter& layer_pb) {
241 if (!Layer::Load(layer_pb)) {
242 AERROR << "Fail to Load the layer parameters!";
243 return false;
244 }
245 if (!layer_pb.has_activation()) {
246 kactivation_ = serialize_to_function("linear");
247 } else {
248 ActivationParameter activation_pb = layer_pb.activation();
249 kactivation_ = serialize_to_function(activation_pb.activation());
250 }
251 return true;
252}
253
254bool Activation::Load(const ActivationParameter& activation_pb) {
255 if (!activation_pb.has_activation()) {
256 kactivation_ = serialize_to_function("linear");
257 } else {
258 kactivation_ = serialize_to_function(activation_pb.activation());
259 }
260 return true;
261}
262
263void Activation::Run(const std::vector<Eigen::MatrixXf>& inputs,
264 Eigen::MatrixXf* output) {
265 CHECK_EQ(inputs.size(), 1U);
266 *output = inputs[0].unaryExpr(kactivation_);
267}
268
269bool BatchNormalization::Load(const LayerParameter& layer_pb) {
270 if (!Layer::Load(layer_pb)) {
271 AERROR << "Fail to Load the layer parameters!";
272 return false;
273 }
274
275 auto bn_pb = layer_pb.batch_normalization();
276 epsilon_ = static_cast<float>(bn_pb.epsilon());
277 axis_ = bn_pb.axis();
278 center_ = bn_pb.center();
279 scale_ = bn_pb.scale();
280 momentum_ = bn_pb.momentum();
281 if (!bn_pb.has_mu() || !LoadTensor(bn_pb.mu(), &mu_)) {
282 AERROR << "Fail to Load mu!";
283 return false;
284 }
285 if (!bn_pb.has_sigma() || !LoadTensor(bn_pb.sigma(), &sigma_)) {
286 AERROR << "Fail to Load sigma!";
287 return false;
288 }
289 if (scale_) {
290 if (!bn_pb.has_gamma() || !LoadTensor(bn_pb.gamma(), &gamma_)) {
291 AERROR << "Fail to Load gamma!";
292 return false;
293 }
294 }
295 if (center_) {
296 if (!bn_pb.has_beta() || !LoadTensor(bn_pb.beta(), &beta_)) {
297 AERROR << "Fail to Load beta!";
298 return false;
299 }
300 }
301 return true;
302}
303
304void BatchNormalization::Run(const std::vector<Eigen::MatrixXf>& inputs,
305 Eigen::MatrixXf* output) {
306 CHECK_EQ(inputs.size(), 1U);
307 Eigen::MatrixXf temp = (inputs[0].rowwise() - mu_.transpose());
308 Eigen::MatrixXf norm =
309 temp.array().rowwise() / (sigma_.array().sqrt() + epsilon_).transpose();
310 if (scale_) {
311 norm = norm.array().rowwise() * gamma_.transpose().array();
312 }
313 if (center_) {
314 norm = norm.rowwise() + beta_.transpose();
315 }
316 *output = norm;
317}
318
319bool LSTM::Load(const LayerParameter& layer_pb) {
320 if (!Layer::Load(layer_pb)) {
321 AERROR << "Fail to Load the layer parameters!";
322 return false;
323 }
324 LSTMParameter lstm_pb = layer_pb.lstm();
325 if (!lstm_pb.has_units()) {
326 ADEBUG << "Fail to Load the number of units.";
327 return false;
328 } else {
329 units_ = lstm_pb.units();
330 }
331 if (!lstm_pb.has_return_sequences()) {
332 ADEBUG << "Set return_sequences at default.";
333 return_sequences_ = false;
334 } else {
335 return_sequences_ = lstm_pb.return_sequences();
336 }
337 if (!lstm_pb.has_stateful()) {
338 ADEBUG << "Set stateful at default.";
339 stateful_ = false;
340 } else {
341 stateful_ = lstm_pb.stateful();
342 }
343 if (!lstm_pb.has_activation()) {
344 ADEBUG << "Set activation function as tanh.";
345 kactivation_ = serialize_to_function("tanh");
346 } else {
347 kactivation_ = serialize_to_function(lstm_pb.activation());
348 }
349 if (!lstm_pb.has_recurrent_activation()) {
350 ADEBUG << "Set recurrent_activation function as hard_tanh.";
351 krecurrent_activation_ = serialize_to_function("hard_tanh");
352 } else {
353 krecurrent_activation_ =
354 serialize_to_function(lstm_pb.recurrent_activation());
355 }
356 if (!lstm_pb.has_use_bias()) {
357 ADEBUG << "Set use_bias as true.";
358 use_bias_ = true;
359 } else {
360 use_bias_ = lstm_pb.use_bias();
361 }
362 if (!lstm_pb.has_unit_forget_bias()) {
363 ADEBUG << "Set unit forget bias as true.";
364 unit_forget_bias_ = true;
365 } else {
366 unit_forget_bias_ = lstm_pb.unit_forget_bias();
367 }
368 if (!lstm_pb.has_weights_input() ||
369 !LoadTensor(lstm_pb.weights_input(), &wi_)) {
370 AERROR << "Fail to Load input weights!";
371 return false;
372 }
373 if (!lstm_pb.has_weights_forget() ||
374 !LoadTensor(lstm_pb.weights_forget(), &wf_)) {
375 AERROR << "Fail to Load forget weights!";
376 return false;
377 }
378 if (!lstm_pb.has_weights_cell() ||
379 !LoadTensor(lstm_pb.weights_cell(), &wc_)) {
380 AERROR << "Fail to Load cell weights!";
381 return false;
382 }
383 if (!lstm_pb.has_weights_output() ||
384 !LoadTensor(lstm_pb.weights_output(), &wo_)) {
385 AERROR << "Fail to Load output weights!";
386 return false;
387 }
388 if (!lstm_pb.has_bias_input() || !LoadTensor(lstm_pb.bias_input(), &bi_)) {
389 AERROR << "Fail to Load input bias!";
390 return false;
391 }
392 if (!lstm_pb.has_bias_forget() || !LoadTensor(lstm_pb.bias_forget(), &bf_)) {
393 AERROR << "Fail to Load forget bias!";
394 return false;
395 }
396 if (!lstm_pb.has_bias_cell() || !LoadTensor(lstm_pb.bias_cell(), &bc_)) {
397 AERROR << "Fail to Load cell bias!";
398 return false;
399 }
400 if (!lstm_pb.has_bias_output() || !LoadTensor(lstm_pb.bias_output(), &bo_)) {
401 AERROR << "Fail to Load output bias!";
402 return false;
403 }
404 if (!lstm_pb.has_recurrent_weights_input() ||
405 !LoadTensor(lstm_pb.recurrent_weights_input(), &r_wi_)) {
406 AERROR << "Fail to Load recurrent input weights!";
407 return false;
408 }
409 if (!lstm_pb.has_recurrent_weights_forget() ||
410 !LoadTensor(lstm_pb.recurrent_weights_forget(), &r_wf_)) {
411 AERROR << "Fail to Load recurrent forget weights!";
412 return false;
413 }
414 if (!lstm_pb.has_recurrent_weights_cell() ||
415 !LoadTensor(lstm_pb.recurrent_weights_cell(), &r_wc_)) {
416 AERROR << "Fail to Load recurrent cell weights!";
417 return false;
418 }
419 if (!lstm_pb.has_recurrent_weights_output() ||
420 !LoadTensor(lstm_pb.recurrent_weights_output(), &r_wo_)) {
421 AERROR << "Fail to Load recurrent output weights!";
422 return false;
423 }
424 ResetState();
425 return true;
426}
427
428void LSTM::Step(const Eigen::MatrixXf& input, Eigen::MatrixXf* output,
429 Eigen::MatrixXf* ht_1, Eigen::MatrixXf* ct_1) {
430 Eigen::MatrixXf x_i = input * wi_ + bi_.transpose();
431 Eigen::MatrixXf x_f = input * wf_ + bf_.transpose();
432 Eigen::MatrixXf x_c = input * wc_ + bc_.transpose();
433 Eigen::MatrixXf x_o = input * wo_ + bo_.transpose();
434
435 Eigen::MatrixXf i = (x_i + (*ht_1) * r_wi_).unaryExpr(krecurrent_activation_);
436 Eigen::MatrixXf f = (x_f + (*ht_1) * r_wf_).unaryExpr(krecurrent_activation_);
437 Eigen::MatrixXf c =
438 f.array() * ct_1->array() +
439 i.array() * ((x_c + (*ht_1) * r_wc_).unaryExpr(kactivation_)).array();
440 Eigen::MatrixXf o = (x_o + (*ht_1) * r_wo_).unaryExpr(krecurrent_activation_);
441 Eigen::MatrixXf h = o.array() * (c.unaryExpr(kactivation_)).array();
442
443 *ht_1 = h;
444 *ct_1 = c;
445 *output = h;
446}
447
448void LSTM::Run(const std::vector<Eigen::MatrixXf>& inputs,
449 Eigen::MatrixXf* output) {
450 CHECK_EQ(inputs.size(), 1U);
451 Eigen::MatrixXf sequences(inputs[0].rows(), units_);
452 Eigen::MatrixXf temp;
453 for (int i = 0; i < inputs[0].rows(); ++i) {
454 Step(inputs[0].row(i), &temp, &ht_1_, &ct_1_);
455 sequences.row(i) = temp.row(0);
456 }
457 if (return_sequences_) {
458 *output = sequences;
459 } else {
460 *output = temp.row(0);
461 }
462}
463
465 ht_1_.resize(1, units_);
466 ct_1_.resize(1, units_);
467 ht_1_.fill(0.0);
468 ct_1_.fill(0.0);
469}
470
471void LSTM::State(std::vector<Eigen::MatrixXf>* states) const {
472 states->resize(2);
473 states->at(0) = ht_1_;
474 states->at(1) = ct_1_;
475}
476
477void LSTM::SetState(const std::vector<Eigen::MatrixXf>& states) {
478 CHECK_EQ(states.size(), 2U);
479 CHECK_EQ(states[0].rows(), 1);
480 CHECK_EQ(states[1].rows(), 1);
481 CHECK_EQ(states[0].cols(), units_);
482 CHECK_EQ(states[1].cols(), units_);
483 ht_1_ = states[0];
484 ct_1_ = states[1];
485}
486
487bool Flatten::Load(const LayerParameter& layer_pb) {
488 if (!Layer::Load(layer_pb)) {
489 AERROR << "Fail to Load the layer parameters!";
490 return false;
491 }
492 return true;
493}
494
495void Flatten::Run(const std::vector<Eigen::MatrixXf>& inputs,
496 Eigen::MatrixXf* output) {
497 CHECK_EQ(inputs.size(), 1U);
498 Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> inp(
499 inputs[0]);
500 inp.resize(1, inp.size());
501 *output = inp;
502}
503
504bool Input::Load(const LayerParameter& layer_pb) {
505 if (!Layer::Load(layer_pb)) {
506 AERROR << "Fail to Load the layer parameters!";
507 return false;
508 }
509 InputParameter input_pb = layer_pb.input();
510 if (input_pb.input_shape_size() < 1) {
511 AERROR << "Fail to Load input shape of InputLayer!";
512 return false;
513 } else {
514 input_shape_.resize(input_pb.input_shape_size());
515 for (int i = 0; i < input_pb.input_shape_size(); ++i) {
516 input_shape_[i] = input_pb.input_shape(i);
517 }
518 }
519 if (!input_pb.has_dtype()) {
520 ADEBUG << "Set the type of input as float!";
521 dtype_ = "float32";
522 } else {
523 dtype_ = input_pb.dtype();
524 }
525 if (!input_pb.has_sparse()) {
526 ADEBUG << "set the sparse of input as false!";
527 sparse_ = false;
528 } else {
529 sparse_ = input_pb.sparse();
530 }
531 return true;
532}
533
534void Input::Run(const std::vector<Eigen::MatrixXf>& inputs,
535 Eigen::MatrixXf* output) {
536 CHECK_EQ(inputs.size(), 1U);
537 CHECK_EQ(inputs[0].cols(), input_shape_.back());
538 *output = inputs[0];
539}
540
541bool Concatenate::Load(const LayerParameter& layer_pb) {
542 if (!Layer::Load(layer_pb)) {
543 AERROR << "Fail to Load the layer parameters!";
544 return false;
545 }
546 ConcatenateParameter concat_pb = layer_pb.concatenate();
547 if (!concat_pb.has_axis()) {
548 AERROR << "Fail to Load the concatenate!";
549 return false;
550 }
551 axis_ = concat_pb.axis();
552 return true;
553}
554
555void Concatenate::Run(const std::vector<Eigen::MatrixXf>& inputs,
556 Eigen::MatrixXf* output) {
557 CHECK_EQ(inputs.size(), 2U);
558 CHECK_EQ(inputs[0].rows(), inputs[1].rows());
559 output->resize(inputs[0].rows(), inputs[0].cols() + inputs[1].cols());
560 *output << inputs[0], inputs[1];
561}
562
563} // namespace network
564} // namespace prediction
565} // namespace apollo
double f
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:263
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the parameter from a pb message
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the dense layer parameter from a pb message
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:219
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:304
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the parameter from a pb message
Definition net_layer.cc:269
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the layer parameter from a pb message
Definition net_layer.cc:541
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:555
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the layer parameter from a pb message
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:129
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the dense layer parameter from a pb message
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:82
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:495
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the dense layer parameter from a pb message
Definition net_layer.cc:487
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the layer parameter from a pb message
Definition net_layer.cc:504
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:534
void SetState(const std::vector< Eigen::MatrixXf > &states) override
Set the internal state and memory cell state
Definition net_layer.cc:477
void ResetState() override
Reset the internal state and memory cell state as zero-matrix
Definition net_layer.cc:464
void State(std::vector< Eigen::MatrixXf > *states) const override
Access to the internal state and memory cell state
Definition net_layer.cc:471
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the layer parameter from a pb message
Definition net_layer.cc:319
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:448
virtual bool Load(const apollo::prediction::LayerParameter &layer_pb)
Load layer parameters from a protobuf message
Definition net_layer.cc:32
void Run(const std::vector< Eigen::MatrixXf > &inputs, Eigen::MatrixXf *output) override
Compute the layer output from inputs
Definition net_layer.cc:176
bool Load(const apollo::prediction::LayerParameter &layer_pb) override
Load the layer parameter from a pb message
#define ACHECK(cond)
Definition log.h:80
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
std::function< float(float)> serialize_to_function(const std::string &str)
translate a string into a network activation function
Definition net_util.cc:56
bool LoadTensor(const TensorParameter &tensor_pb, Eigen::MatrixXf *matrix)
load matrix value from a protobuf message
Definition net_util.cc:66
class register implement
Definition arena_queue.h:37
optional string activation
optional int32 kernel_size
optional int32 stride
optional TensorParameter bias
optional int32 stride
optional TensorParameter kernel
optional bool use_bias
optional string activation
optional bool use_bias
optional TensorParameter weights
optional int32 units
optional TensorParameter bias
repeated int32 input_shape
optional string dtype
optional bool sparse
optional int32 stride
optional int32 kernel_size