37 {
38 paddle_infer::Config config;
39 config.SetModel(model_file_, params_file_);
40
43 }
44
45 if (FLAGS_use_trt) {
46 paddle::AnalysisConfig::Precision precision;
47 if (FLAGS_trt_precision == 0) {
48 precision = paddle_infer::PrecisionType::kFloat32;
49 } else if (FLAGS_trt_precision == 1) {
50 precision = paddle_infer::PrecisionType::kInt8;
51 } else if (FLAGS_trt_precision == 2) {
52 precision = paddle_infer::PrecisionType::kHalf;
53 } else {
54 AERROR <<
"Tensorrt type can only support 0, 1, 2, but recieved is"
55 << FLAGS_trt_precision << "\n";
56 return false;
57 }
58 config.EnableTensorRtEngine(1 << 30, 1, 3, precision, FLAGS_trt_use_static,
59 FLAGS_use_calibration);
60
61 if (FLAGS_collect_shape_info) {
62 config.CollectShapeRangeInfo(FLAGS_dynamic_shape_file);
63 }
64
65 if (FLAGS_use_dynamicshape)
66 config.EnableTunedTensorRtDynamicShape(FLAGS_dynamic_shape_file, true);
67 }
68
69 config.EnableMemoryOptim();
70 config.SwitchIrOptim(true);
71 predictor_ = paddle_infer::CreatePredictor(config);
73 return false;
74 }
75
76
77 auto input_names =
predictor_->GetInputNames();
78 auto output_names =
predictor_->GetOutputNames();
79
80 std::vector<std::string> exist_names;
81 for (const std::string& name : input_names_) {
82 if (std::find(input_names.begin(), input_names.end(), name) !=
83 input_names.end()) {
84 exist_names.push_back(name);
85 }
86 }
87 input_names_ = exist_names;
88
89 exist_names.clear();
90 for (const std::string& name : output_names_) {
91 if (std::find(output_names.begin(), output_names.end(), name) !=
92 output_names.end()) {
93 exist_names.push_back(name);
94 }
95 }
96 output_names_ = exist_names;
97
98
99 for (
const auto&
shape : shapes) {
100 auto blob =
101 std::make_shared<apollo::perception::base::Blob<float>>(
shape.second);
102 blobs_.emplace(
shape.first, blob);
103 }
104
105 return true;
106}
bool shape(const std::string &name, std::vector< int > *res)
constexpr uint64_t MemoryPoolInitSizeMb