Apollo 10.0
自动驾驶开放平台
apollo::prediction::ModelManager类 参考

#include <model_manager.h>

apollo::prediction::ModelManager 的协作图:

Public 成员函数

 ModelManager ()
 
 ~ModelManager ()
 
bool Init ()
 init model manager add load all defined plugin
 
std::shared_ptr< ModelBaseSelectModel (const Model::Backend &backend, const ObstacleConf::EvaluatorType &evaluator_type, const apollo::perception::PerceptionObstacle::Type &obstacle_type)
 select the best model
 

详细描述

在文件 model_manager.h35 行定义.

构造及析构函数说明

◆ ModelManager()

apollo::prediction::ModelManager::ModelManager ( )

在文件 model_manager.cc29 行定义.

29 {
30 PredictionConf prediciton_conf;
32 FLAGS_prediction_conf_file, &prediciton_conf)) {
33 AERROR << "Unable to load prediction conf file: "
34 << FLAGS_prediction_conf_file;
35 ACHECK(false);
36 }
37 evaluator_model_conf_ = prediciton_conf.evaluator_model_conf();
38 models_ = std::map<std::string, std::vector<std::shared_ptr<ModelBase>>>{};
39}
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132

◆ ~ModelManager()

apollo::prediction::ModelManager::~ModelManager ( )
inline

在文件 model_manager.h38 行定义.

38{}

成员函数说明

◆ Init()

bool apollo::prediction::ModelManager::Init ( )

init model manager add load all defined plugin

返回
init result, true for success

在文件 model_manager.cc41 行定义.

41 {
42 static const std::string class_namespace = "apollo::prediction::";
43 std::map<std::string, std::vector<Model>> m;
44 for (auto& model_conf : evaluator_model_conf_.model()) {
45 auto key = to_string(model_conf);
46 if (model_conf.priority() == 0) {
47 // priority = 0 means this plugin only applicable to arm arch
48 #ifndef __aarch64__
49 continue;
50 #endif
51 }
52 if (m.find(key) != m.end()) {
53 m[key].push_back(model_conf);
54 } else {
55 m[key] = std::vector<Model>{model_conf};
56 }
57 }
58
59 // sort the model based on priority
60 for (auto& p : m) {
61 sort(m[p.first].begin(), m[p.first].end(),
62 [](Model& a, Model& b){return a.priority() < b.priority();});
63 }
64
65 for (auto& p : m) {
66 auto key = p.first;
67 auto& model_conf_vec = p.second;
68 models_[key] = std::vector<std::shared_ptr<ModelBase>>{};
69 for (auto model_conf : model_conf_vec) {
70 std::string class_name = model_conf.type();
71 if (class_name.find("::") == std::string::npos) {
72 class_name = class_namespace + class_name;
73 }
74 auto model_ptr =
76 ->CreateInstance<ModelBase>(class_name);
77 models_[key].push_back(model_ptr);
78 }
79 }
80
81 return true;
82}
static PluginManager * Instance()
get singleton instance of PluginManager
std::shared_ptr< Base > CreateInstance(const std::string &derived_class)
create plugin instance of derived class based on Base

◆ SelectModel()

std::shared_ptr< ModelBase > apollo::prediction::ModelManager::SelectModel ( const Model::Backend backend,
const ObstacleConf::EvaluatorType evaluator_type,
const apollo::perception::PerceptionObstacle::Type obstacle_type 
)

select the best model

参数
backendinference backend of model
evaluator_typethe type of evaluator
obstacle_typethe type of obstacle
返回
shared ptr of the model

在文件 model_manager.cc100 行定义.

104 {
105 auto key = to_string(backend, evaluator_type, obstacle_type);
106 if (models_.find(key) == models_.end()) {
107 AERROR << "Can't find model with attribute: evaluator_type("
108 << evaluator_type << ") " << "obstacle_type(" << obstacle_type
109 << ") " << "backend(" << backend << ")";
110 ACHECK(false);
111 }
112 return models_[key][0];
113}

该类的文档由以下文件生成: