Apollo 10.0
自动驾驶开放平台
apollo::perception::camera::ExternalFeatureExtractor类 参考

#include <external_feature_extractor.h>

类 apollo::perception::camera::ExternalFeatureExtractor 继承关系图:
apollo::perception::camera::ExternalFeatureExtractor 的协作图:

Public 成员函数

 ExternalFeatureExtractor ()=default
 
 ~ExternalFeatureExtractor ()=default
 
bool Init (const FeatureExtractorInitOptions &init_options) override
 
bool Extract (const FeatureExtractorOptions &options, CameraTrackingFrame *frame) override
 
- Public 成员函数 继承自 apollo::perception::camera::BaseFeatureExtractor
 BaseFeatureExtractor ()=default
 
virtual ~BaseFeatureExtractor ()=default
 
void set_roi (int x, int y, int w, int h)
 
void decode_bbox (std::vector< std::shared_ptr< base::Object > > *objects)
 
void encode_bbox (std::vector< std::shared_ptr< base::Object > > *objects)
 

额外继承的成员函数

- Protected 属性 继承自 apollo::perception::camera::BaseFeatureExtractor
std::shared_ptr< base::Blob< float > > feat_blob_ = nullptr
 
int roi_x_ = 0
 
int roi_y_ = 0
 
int roi_w_ = 0
 
int roi_h_ = 0
 

详细描述

在文件 external_feature_extractor.h30 行定义.

构造及析构函数说明

◆ ExternalFeatureExtractor()

apollo::perception::camera::ExternalFeatureExtractor::ExternalFeatureExtractor ( )
default

◆ ~ExternalFeatureExtractor()

apollo::perception::camera::ExternalFeatureExtractor::~ExternalFeatureExtractor ( )
default

成员函数说明

◆ Extract()

bool apollo::perception::camera::ExternalFeatureExtractor::Extract ( const FeatureExtractorOptions options,
CameraTrackingFrame frame 
)
overridevirtual

实现了 apollo::perception::camera::BaseFeatureExtractor.

在文件 external_feature_extractor.cc100 行定义.

101 {
102 int raw_height = frame->data_provider->src_height();
103 int raw_width = frame->data_provider->src_width();
104 auto input_blob = net_->get_blob(model_param_.info().inputs(0).name());
105 DataProvider::ImageOptions image_options;
106 image_options.target_color = base::Color::BGR;
107 auto offset_y_ = static_cast<int>(
108 model_param_.offset_ratio() * static_cast<float>(raw_height) + 0.5f);
109 image_options.crop_roi =
110 base::RectI(0, offset_y_, raw_width, raw_height - offset_y_);
111 image_options.do_crop = true;
112 // Timer timer;
113 frame->data_provider->GetImage(image_options, image_.get());
114 inference::ResizeGPU(*image_, input_blob, raw_width, 0);
115 net_->Infer();
116 FeatureExtractorOptions feat_options;
117 feat_options.normalized = false;
118 feature_extractor_->set_roi(
119 image_options.crop_roi.x, image_options.crop_roi.y,
120 image_options.crop_roi.width, image_options.crop_roi.height);
121 feature_extractor_->Extract(feat_options, frame);
122 AINFO << "Extract Done";
123 return true;
124}
#define AINFO
Definition log.h:42
Rect< int > RectI
Definition box.h:159
bool ResizeGPU(const base::Image8U &src, std::shared_ptr< apollo::perception::base::Blob< float > > dst, int stepwidth, int start_axis)

◆ Init()

bool apollo::perception::camera::ExternalFeatureExtractor::Init ( const FeatureExtractorInitOptions init_options)
overridevirtual

实现了 apollo::perception::camera::BaseFeatureExtractor.

在文件 external_feature_extractor.cc33 行定义.

34 {
35 std::string config_file =
36 GetConfigFile(options.config_path, options.config_file);
37 if (!cyber::common::GetProtoFromFile(config_file, &model_param_)) {
38 AERROR << "Read config failed: " << config_file;
39 return false;
40 }
41
42 AINFO << "Load config Success: " << model_param_.ShortDebugString();
43
44 const auto &model_info = model_param_.info();
45 std::string model_path = GetModelPath(model_info.name());
46 std::string proto_file =
47 GetModelFile(model_path, model_info.proto_file().file());
48 std::string weight_file =
49 GetModelFile(model_path, model_info.weight_file().file());
50
51 // Network input and output names
52 std::vector<std::string> input_names =
53 inference::GetBlobNames(model_info.inputs());
54 std::vector<std::string> output_names =
55 inference::GetBlobNames(model_info.outputs());
56
57 height_ = model_param_.resize().height();
58 width_ = model_param_.resize().width();
59
61 model_info.framework(), proto_file, weight_file, output_names,
62 input_names, model_path));
63 ACHECK(nullptr != net_) << "Failed to init CNNAdapter";
64
65 gpu_id_ = GlobalConfig::Instance()->track_feature_gpu_id;
66 net_->set_gpu_id(gpu_id_);
67
68 std::map<std::string, std::vector<int>> shape_map;
69 inference::AddShape(&shape_map, model_info.inputs());
70 inference::AddShape(&shape_map, model_info.outputs());
71 if (!net_->Init(shape_map)) {
72 AERROR << model_info.name() << "init failed!";
73 return false;
74 }
75
76 net_->Infer();
77
78 InitFeatureExtractor(options);
79 image_.reset(new base::Image8U(height_, width_, base::Color::BGR));
80 return true;
81}
#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
std::vector< std::string > GetBlobNames(const google::protobuf::RepeatedPtrField< common::ModelBlob > &model_blobs)
Definition model_util.cc:23
void AddShape(std::map< std::string, std::vector< int > > *shape_map, const google::protobuf::RepeatedPtrField< common::ModelBlob > &model_blobs)
Definition model_util.cc:32
Inference * CreateInferenceByName(const std::string &frame_work, const std::string &proto_file, const std::string &weight_file, const std::vector< std::string > &outputs, const std::vector< std::string > &inputs, const std::string &model_root)
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
Definition util.cc:55
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
Definition util.cc:44

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