Apollo 11.0
自动驾驶开放平台
mi_common.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2022 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
19#include <utility>
20
21#include "absl/strings/str_cat.h"
22
23namespace apollo {
24namespace perception {
25namespace inference {
26
27void ParseNetParam(const NetParameter &net_param,
28 TensorDimsMap *tensor_dims_map,
29 std::map<std::string, std::string> *tensor_modify_map,
30 std::vector<LayerParameter> *order) {
31 for (int i = 0; i < net_param.layer_size(); ++i) {
32 LayerParameter tensorrt_layer_param = net_param.layer(i);
33 if (tensorrt_layer_param.type() == "Input") {
34 InputParameter input = tensorrt_layer_param.input_param();
35 for (int j = 0; j < tensorrt_layer_param.top().size(); ++j) {
36 TensorDims dims{static_cast<int>(input.shape(j).dim(0)),
37 static_cast<int>(input.shape(j).dim(1)),
38 static_cast<int>(input.shape(j).dim(2)),
39 static_cast<int>(input.shape(j).dim(3))};
40 auto name = tensorrt_layer_param.top(j);
41 tensor_dims_map->insert(std::make_pair(name, dims));
42 tensor_modify_map->insert(
43 std::make_pair(name, tensorrt_layer_param.top(j)));
44 }
45 } else {
46 order->push_back(tensorrt_layer_param);
47 }
48 }
49}
50
52 if (conv.has_kernel_h() || conv.has_kernel_w()) {
53 if (conv.kernel_size_size() != 0) {
54 return false;
55 }
56 param->kernel_h = conv.kernel_h();
57 param->kernel_w = conv.kernel_w();
58 } else {
59 if (conv.kernel_size_size() < 1) {
60 return false;
61 }
62 param->kernel_h = conv.kernel_size(0);
63 param->kernel_w = (conv.kernel_size_size() > 1 ? conv.kernel_size(1)
64 : conv.kernel_size(0));
65 }
66 if (param->kernel_h == 0 || param->kernel_w == 0) {
67 return false;
68 }
69
70 if (conv.has_pad_h() || conv.has_pad_w()) {
71 if (conv.pad_size() != 0) {
72 return false;
73 }
74 param->padding_h = conv.pad_h();
75 param->padding_w = conv.pad_w();
76 } else {
77 param->padding_h = (conv.pad().empty() ? 0 : conv.pad(0));
78 param->padding_w = (conv.pad_size() > 1 ? conv.pad(1) : param->padding_h);
79 }
80
81 if (conv.has_stride_h() || conv.has_stride_w()) {
82 if (conv.stride_size() != 0) {
83 return false;
84 }
85 param->stride_h = conv.stride_h();
86 param->stride_w = conv.stride_w();
87 } else {
88 param->stride_h = (conv.stride().empty() ? 1 : conv.stride(0));
89 param->stride_w =
90 (conv.stride_size() > 1 ? conv.stride(1) : param->stride_h);
91 }
92 if (param->stride_h == 0 || param->stride_w == 0) {
93 return false;
94 }
95
96 param->dilation = conv.dilation().empty() ? 1 : conv.dilation(0);
97 param->group = conv.has_group() ? conv.group() : 1;
98 return true;
99}
100
102 if (pool_param->has_kernel_size()) {
103 pool_param->set_kernel_h(pool_param->kernel_size());
104 pool_param->set_kernel_w(pool_param->kernel_size());
105 }
106 if (pool_param->kernel_w() == 0 || pool_param->kernel_h() == 0) {
107 return false;
108 }
109 if (pool_param->has_pad()) {
110 pool_param->set_pad_h(pool_param->pad());
111 pool_param->set_pad_w(pool_param->pad());
112 }
113 if (pool_param->has_stride()) {
114 pool_param->set_stride_h(pool_param->stride());
115 pool_param->set_stride_w(pool_param->stride());
116 }
117 if (pool_param->stride_w() == 0 || pool_param->stride_h() == 0) {
118 return false;
119 }
120 return true;
121}
122
123} // namespace inference
124} // namespace perception
125} // namespace apollo
bool ParserConvParam(const ConvolutionParameter &conv, ConvParam *param)
Definition mi_common.cc:51
void ParseNetParam(const NetParameter &net_param, TensorDimsMap *tensor_dims_map, std::map< std::string, std::string > *tensor_modify_map, std::vector< LayerParameter > *order)
Definition mi_common.cc:27
std::vector< int > TensorDims
Definition mi_common.h:32
std::map< std::string, TensorDims > TensorDimsMap
Definition mi_common.h:33
bool modify_pool_param(PoolingParameter *pool_param)
Definition mi_common.cc:101
class register implement
Definition arena_queue.h:37