Apollo 10.0
自动驾驶开放平台
inference.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 <map>
20#include <memory>
21#include <string>
22#include <vector>
23
26
27#if GPU_PLATFORM == NVIDIA
28 #include <c10/cuda/CUDACachingAllocator.h>
29 using c10::cuda::CUDACachingAllocator::emptyCache;
30#elif GPU_PLATFORM == AMD
31 #include <c10/hip/HIPCachingAllocator.h>
32 using c10::hip::HIPCachingAllocator::emptyCache;
33#endif
34
35namespace apollo {
36namespace perception {
37namespace inference {
38
39typedef std::map<std::string, base::BlobPtr<float>> BlobMap;
40
41class Inference {
42 public:
43 Inference() = default;
44
45 virtual ~Inference() = default;
46
47 virtual bool Init(const std::map<std::string, std::vector<int>> &shapes) = 0;
48
49 virtual void Infer() = 0;
50
51 virtual base::BlobPtr<float> get_blob(const std::string &name) = 0;
52
53 void set_max_batch_size(const int &batch_size);
54
55 void set_gpu_id(const int &gpu_id);
56
57 void set_model_info(const std::string &proto_file,
58 const std::vector<std::string> &net_input_names,
59 const std::vector<std::string> &net_output_names);
60
61 protected:
63 int gpu_id_ = 0;
64 std::string proto_file_ = "";
65 std::vector<std::string> net_output_names_;
66 std::vector<std::string> net_input_names_;
67};
68
69} // namespace inference
70} // namespace perception
71} // namespace apollo
std::vector< std::string > net_input_names_
Definition inference.h:66
std::vector< std::string > net_output_names_
Definition inference.h:65
virtual bool Init(const std::map< std::string, std::vector< int > > &shapes)=0
virtual base::BlobPtr< float > get_blob(const std::string &name)=0
void set_model_info(const std::string &proto_file, const std::vector< std::string > &net_input_names, const std::vector< std::string > &net_output_names)
Definition inference.cc:29
void set_max_batch_size(const int &batch_size)
Definition inference.cc:23
void set_gpu_id(const int &gpu_id)
Definition inference.cc:27
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