Apollo 11.0
自动驾驶开放平台
onnx_multi_batch_infer.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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
17#pragma once
18
19#include <NvInferPlugin.h>
20#include <NvInferRuntimeCommon.h>
21#include <NvInferVersion.h>
22
23#include <iostream>
24#include <map>
25#include <memory>
26#include <string>
27#include <utility>
28#include <vector>
29
30#include "NvInfer.h"
31#include "NvOnnxParser.h"
32
36
37namespace apollo {
38namespace perception {
39namespace inference {
40
42public:
44
45 virtual ~MultiBatchInference();
46
52 bool OnnxToTRTModel(const std::string &model_file);
53
54 void SetOnnxOptimizationProfile(nvinfer1::IOptimizationProfile *profile, const BlobMap &input_shapes);
55
56 void inference();
57 bool LoadCache(const std::string &path);
58 bool Init(const std::map<std::string, std::vector<int>> &shapes) override;
59 void Infer() override;
60 void init_blob(std::vector<std::string> *names);
61 base::BlobPtr<float> get_blob(const std::string &name) override;
62
63 void FileInit();
64
65 void SetStream(cudaStream_t stream) {
66 stream_ = stream;
67 }
68
69private:
70 std::string model_file_;
71 float score_threshold_;
72 std::vector<std::string> output_names_;
73 std::vector<std::string> input_names_;
74 BlobMap blobs_;
75
76 std::mutex mutex_;
77 int bindingIndex_ = 0;
78 nvinfer1::INetworkDefinition *network_ = nullptr;
79 nvinfer1::ICudaEngine *engine_ = nullptr;
80 nvinfer1::IExecutionContext *context_ = nullptr;
81 nvinfer1::IBuilder *builder_ = nullptr;
82
83 std::vector<void *> buffers_;
84 cudaStream_t stream_ = 0;
85 int workspaceSize_ = 1;
86
87 int num_classes_;
88 int kBatchSize;
89 bool dynamic_flag_ = false;
90};
91
95} // namespace inference
96} // namespace perception
97} // namespace apollo
bool OnnxToTRTModel(const std::string &model_file)
Convert ONNX to TensorRT model
void init_blob(std::vector< std::string > *names)
void SetOnnxOptimizationProfile(nvinfer1::IOptimizationProfile *profile, const BlobMap &input_shapes)
bool Init(const std::map< std::string, std::vector< int > > &shapes) override
base::BlobPtr< float > get_blob(const std::string &name) override
#define CYBER_PLUGIN_MANAGER_REGISTER_PLUGIN(name, base)
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition blob.h:313
std::map< std::string, base::BlobPtr< float > > BlobMap
Definition inference.h:39
class register implement
Definition arena_queue.h:37