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

#include <tracking_feat_extractor.h>

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

Public 成员函数

 TrackingFeatureExtractor ()=default
 
 ~TrackingFeatureExtractor ()=default
 
bool Init (const FeatureExtractorInitOptions &init_options) override
 init feature extractor
 
bool Extract (const FeatureExtractorOptions &options, CameraTrackingFrame *frame) override
 extract feature from frame
 
- 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 成员函数

void init_roipooling (const tracking_feature::ROIPoolingParam &param)
 

Protected 属性

std::vector< std::shared_ptr< FeatureExtractorLayer > > roi_poolings_
 
inference::GPUL2Norm norm_
 
int input_height_ = 0
 
int input_width_ = 0
 
int feat_width_ = 0
 
int feat_height_ = 0
 
- 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
 

详细描述

在文件 tracking_feat_extractor.h42 行定义.

构造及析构函数说明

◆ TrackingFeatureExtractor()

apollo::perception::camera::TrackingFeatureExtractor::TrackingFeatureExtractor ( )
default

◆ ~TrackingFeatureExtractor()

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

成员函数说明

◆ Extract()

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

extract feature from frame

参数
options
frame
返回
true
false

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

在文件 tracking_feat_extractor.cc94 行定义.

95 {
96 if (frame == nullptr) {
97 return false;
98 }
99 if (frame->detected_objects.empty()) {
100 return true;
101 }
102 if (!options.normalized) {
103 // normalize bbox
104 encode_bbox(&(frame->detected_objects));
105 }
106 auto feat_blob = frame->feature_blob;
107 for (auto feature_extractor_layer_ptr : roi_poolings_) {
108 feature_extractor_layer_ptr->rois_blob->Reshape(
109 {static_cast<int>(frame->detected_objects.size()), 5});
110 float *rois_data =
111 feature_extractor_layer_ptr->rois_blob->mutable_cpu_data();
112 for (const auto &obj : frame->detected_objects) {
113 rois_data[0] = 0;
114 rois_data[1] =
115 obj->camera_supplement.box.xmin * static_cast<float>(feat_width_);
116 rois_data[2] =
117 obj->camera_supplement.box.ymin * static_cast<float>(feat_height_);
118 rois_data[3] =
119 obj->camera_supplement.box.xmax * static_cast<float>(feat_width_);
120 rois_data[4] =
121 obj->camera_supplement.box.ymax * static_cast<float>(feat_height_);
122 ADEBUG << rois_data[0] << " " << rois_data[1] << " " << rois_data[2]
123 << " " << rois_data[3] << " " << rois_data[4];
124 rois_data += feature_extractor_layer_ptr->rois_blob->offset(1);
125 }
126
127 // obtain the track feature blob
128 feature_extractor_layer_ptr->pooling_layer->ForwardGPU(
129 {feat_blob, feature_extractor_layer_ptr->rois_blob},
130 {frame->track_feature_blob});
131
132 if (!options.normalized) {
133 // denormalize bbox
134 decode_bbox(&(frame->detected_objects));
135 }
136 }
137 norm_.L2Norm(frame->track_feature_blob.get());
138 return true;
139}
void encode_bbox(std::vector< std::shared_ptr< base::Object > > *objects)
void decode_bbox(std::vector< std::shared_ptr< base::Object > > *objects)
std::vector< std::shared_ptr< FeatureExtractorLayer > > roi_poolings_
void L2Norm(base::Blob< float > *input_data)
#define ADEBUG
Definition log.h:41

◆ Init()

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

init feature extractor

参数
init_options
返回
true
false

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

在文件 tracking_feat_extractor.cc25 行定义.

26 {
27 tracking_feature::FeatureParam feat_param;
28 std::string config_file =
29 GetConfigFile(options.config_path, options.config_file);
30
31 if (!cyber::common::GetProtoFromFile(config_file, &feat_param)) {
32 AERROR << "Read feature extractor config file failed!";
33 return false;
34 }
35 if (feat_param.extractor_size() != 1) {
36 AERROR << "extractor should be 1";
37 return false;
38 }
39
40 const std::string feat_blob_name = feat_param.feat_blob_name();
41 const auto &feat_blob_shape_pb = feat_param.feat_blob_shape();
42
43 std::vector<int> feat_blob_shape(feat_blob_shape_pb.begin(),
44 feat_blob_shape_pb.end());
46 std::make_shared<apollo::perception::base::Blob<float>>(feat_blob_shape);
47
48 // setup bottom and top
49 int feat_height = feat_blob_->shape(2);
50 int feat_width = feat_blob_->shape(3);
51
53 options.input_height == 0 ? feat_height : options.input_height;
54 input_width_ = options.input_width == 0 ? feat_width : options.input_width;
55
56 CHECK_EQ(input_height_ / feat_height, input_width_ / feat_width)
57 << "Invalid aspect ratio: " << feat_height << "x" << feat_width
58 << " from " << input_height_ << "x" << input_width_;
59 for (int i = 0; i < feat_param.extractor_size(); i++) {
60 switch (feat_param.extractor(i).feat_type()) {
61 case tracking_feature::ExtractorParam_FeatureType_ROIPooling:
62 init_roipooling(feat_param.extractor(i).roi_pooling_param());
63 break;
64 }
65 }
66 if (roi_poolings_.empty()) {
67 AERROR << "no proper extractor";
68 return false;
69 }
70 return true;
71}
std::shared_ptr< base::Blob< float > > feat_blob_
void init_roipooling(const tracking_feature::ROIPoolingParam &param)
#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::string GetConfigFile(const std::string &config_path, const std::string &config_file)
Definition util.cc:80

◆ init_roipooling()

void apollo::perception::camera::TrackingFeatureExtractor::init_roipooling ( const tracking_feature::ROIPoolingParam param)
protected

在文件 tracking_feat_extractor.cc73 行定义.

74 {
75 int feat_channel = feat_blob_->shape(1);
76 feat_height_ = feat_blob_->shape(2);
77 feat_width_ = feat_blob_->shape(3);
78
79 std::shared_ptr<FeatureExtractorLayer> feature_extractor_layer_ptr;
80 feature_extractor_layer_ptr.reset(new FeatureExtractorLayer());
81 std::vector<int> shape{1, 5};
82 feature_extractor_layer_ptr->rois_blob.reset(new base::Blob<float>(shape));
83 int pooled_w = param.pooled_w();
84 int pooled_h = param.pooled_h();
85 bool use_floor = param.use_floor();
86 feature_extractor_layer_ptr->pooling_layer.reset(
87 new inference::ROIPoolingLayer<float>(pooled_h, pooled_w, use_floor, 1,
88 feat_channel));
89 feature_extractor_layer_ptr->top_blob.reset(
90 new base::Blob<float>(1, feat_blob_->channels(), pooled_h, pooled_w));
91 roi_poolings_.push_back(feature_extractor_layer_ptr);
92}

类成员变量说明

◆ feat_height_

int apollo::perception::camera::TrackingFeatureExtractor::feat_height_ = 0
protected

在文件 tracking_feat_extractor.h73 行定义.

◆ feat_width_

int apollo::perception::camera::TrackingFeatureExtractor::feat_width_ = 0
protected

在文件 tracking_feat_extractor.h72 行定义.

◆ input_height_

int apollo::perception::camera::TrackingFeatureExtractor::input_height_ = 0
protected

在文件 tracking_feat_extractor.h70 行定义.

◆ input_width_

int apollo::perception::camera::TrackingFeatureExtractor::input_width_ = 0
protected

在文件 tracking_feat_extractor.h71 行定义.

◆ norm_

inference::GPUL2Norm apollo::perception::camera::TrackingFeatureExtractor::norm_
protected

在文件 tracking_feat_extractor.h69 行定义.

◆ roi_poolings_

std::vector<std::shared_ptr<FeatureExtractorLayer> > apollo::perception::camera::TrackingFeatureExtractor::roi_poolings_
protected

在文件 tracking_feat_extractor.h68 行定义.


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