38 offset_y_ =
static_cast<int>(std::round(offset_ratio * image_height));
39 float roi_ratio = cropped_ratio * image_height / image_width;
40 width_ = (resized_width + aligned_pixel / 2) / aligned_pixel * aligned_pixel;
41 height_ =
static_cast<int>(width_ * roi_ratio + aligned_pixel / 2) /
42 aligned_pixel * aligned_pixel;
44 AINFO <<
"image_height=" << image_height <<
", image_width=" << image_width
45 <<
", roi_ratio=" << roi_ratio;
46 AINFO <<
"offset_y=" << offset_y_ <<
", height=" << height_
47 <<
", width=" << width_;
55 auto min_dims = model_param.
min_dims();
66 const auto &nms_param = model_param.
nms_param();
67 nms_.
sigma = nms_param.sigma();
68 nms_.
type = nms_param.type();
75 auto obj_blob_scale1 =
net_->get_blob(
"obj_pred");
76 auto obj_blob_scale2 =
net_->get_blob(
"det2_obj_blob");
77 auto obj_blob_scale3 =
net_->get_blob(
"det3_obj_blob");
78 int output_height_scale1 = obj_blob_scale1->shape(1);
79 int output_width_scale1 = obj_blob_scale1->shape(2);
80 int obj_size = output_height_scale1 * output_width_scale1 *
83 if (obj_blob_scale2) {
84 int output_height_scale2 = obj_blob_scale2->shape(1);
85 int output_width_scale2 = obj_blob_scale2->shape(2);
86 int output_height_scale3 = obj_blob_scale3->shape(1);
87 int output_width_scale3 = obj_blob_scale3->shape(2);
88 obj_size = (output_height_scale1 * output_width_scale1 +
89 output_height_scale2 * output_width_scale2 +
90 output_height_scale3 * output_width_scale3) *
97 1, 1,
static_cast<int>(types_.size() + 1), obj_size));
101 overlapped_->cpu_data();
102 overlapped_->gpu_data();
108 auto expand_cpu_data = yolo_blobs_.
expand_blob->mutable_cpu_data();
109 memcpy(expand_cpu_data, expands_.data(), expands_.size() *
sizeof(
float));
110 auto anchor_cpu_data = yolo_blobs_.
anchor_blob->mutable_cpu_data();
111 memcpy(anchor_cpu_data, anchors_.data(), anchors_.size() *
sizeof(
float));
154 BASE_GPU_CHECK(cudaSetDevice(gpu_id_));
155 BASE_GPU_CHECK(cudaStreamCreate(&stream_));
157 std::string config_file =
160 AERROR <<
"Read proto_config failed! " << config_file;
164 const auto &model_info = model_param_.
info();
165 std::string model_path =
GetModelPath(model_info.name());
166 std::string anchors_file =
167 GetModelFile(model_path, model_info.anchors_file().file());
168 std::string types_file =
169 GetModelFile(model_path, model_info.types_file().file());
170 std::string expand_file =
171 GetModelFile(model_path, model_info.expand_file().file());
185 ACHECK(expands_.size() == types_.size());
188 AERROR <<
"Init network failed!";
197 if (frame ==
nullptr) {
201 if (cudaSetDevice(gpu_id_) != cudaSuccess) {
202 AERROR <<
"Failed to set device to " << gpu_id_;
206 auto model_inputs = model_param_.
info().inputs();
207 auto input_blob =
net_->get_blob(model_inputs[0].name());
224 light_vis_conf_threshold_, light_swt_conf_threshold_,
239 static_cast<int>(border_ratio_ *
static_cast<float>(image.
cols()));
240 int right_boundary =
static_cast<int>((1.0f - border_ratio_) *
241 static_cast<float>(image.
cols()));
244 obj->camera_supplement.alpha /= ori_cycle_;
247 obj->camera_supplement.area_id =
248 get_area_id(obj->camera_supplement.visible_ratios);
251 auto &box = obj->camera_supplement.box;
252 if (box.xmin >= left_boundary) {
253 obj->camera_supplement.cut_off_ratios[2] = 0;
255 if (box.xmax <= right_boundary) {
256 obj->camera_supplement.cut_off_ratios[3] = 0;
#define REGISTER_OBSTACLE_DETECTOR(name)
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
A wrapper around Blob holders serving as the basic computational unit for images.
virtual bool InitNetwork(const common::ModelInfo &model_info, const std::string &model_root)
Interface for network initialization
std::shared_ptr< inference::Inference > net_
bool Detect(onboard::CameraFrame *frame) override
Get obstacles detection result, detector main part
bool Init(const ObstacleDetectorInitOptions &options=ObstacleDetectorInitOptions()) override
Load obstacle detector configs
void LoadInputShape(const yolo::ModelParam &model_param)
void LoadParam(const yolo::ModelParam &model_param)
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,...
void recover_bbox(int roi_w, int roi_h, int offset_y, std::vector< base::ObjectPtr > *objects)
recover detect bbox result to raw image
int get_area_id(float visible_ratios[4])
calculate the area id based on the visible ratios
bool LoadTypes(const std::string &path, std::vector< base::ObjectSubType > *types)
constexpr int anchorSizeFactor
void get_objects_cpu(const YoloBlobs &yolo_blobs, const cudaStream_t &stream, const std::vector< base::ObjectSubType > &types, const NMSParam &nms, const yolo::ModelParam &model_param, float light_vis_conf_threshold, float light_swt_conf_threshold, base::Blob< bool > *overlapped, base::Blob< int > *idx_sm, std::vector< base::ObjectPtr > *objects)
Get the objects cpu object
void filter_bbox(const MinDims &min_dims, std::vector< base::ObjectPtr > *objects)
filter out the objects in the object array based on the given minimum dimension conditions and retain...
bool LoadAnchors(const std::string &path, std::vector< float > *anchors)
bool LoadExpand(const std::string &path, std::vector< float > *expands)
bool ResizeGPU(const base::Image8U &src, std::shared_ptr< apollo::perception::base::Blob< float > > dst, int stepwidth, int start_axis)
std::string GetModelFile(const std::string &model_name, const std::string &file_name)
Get the model file path by model path and file name
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
std::string GetModelPath(const std::string &model_name)
Get the model path by model name, search from APOLLO_MODEL_PATH
float inter_cls_conf_thresh
float inter_cls_nms_thresh
std::shared_ptr< base::Blob< float > > area_id_blob
std::shared_ptr< base::Blob< float > > lof_blob
std::shared_ptr< base::Blob< float > > det3_dim_blob
std::shared_ptr< base::Blob< float > > det2_obj_blob
std::shared_ptr< base::Blob< float > > det3_ori_conf_blob
std::shared_ptr< base::Blob< float > > expand_blob
std::shared_ptr< base::Blob< float > > visible_ratio_blob
std::shared_ptr< base::Blob< float > > det3_cls_blob
std::shared_ptr< base::Blob< float > > ltvis_blob
std::shared_ptr< base::Blob< float > > res_cls_blob
std::shared_ptr< base::Blob< float > > res_box_blob
std::shared_ptr< base::Blob< float > > det3_loc_blob
std::shared_ptr< base::Blob< float > > feat_blob
std::shared_ptr< base::Blob< float > > det1_loc_blob
std::shared_ptr< base::Blob< float > > det1_cls_blob
std::shared_ptr< base::Blob< float > > det1_dim_blob
std::shared_ptr< base::Blob< float > > lor_blob
std::shared_ptr< base::Blob< float > > anchor_blob
std::shared_ptr< base::Blob< float > > det3_obj_blob
std::shared_ptr< base::Blob< float > > brswt_blob
std::shared_ptr< base::Blob< float > > det1_ori_conf_blob
std::shared_ptr< base::Blob< float > > ltswt_blob
std::shared_ptr< base::Blob< float > > det2_ori_blob
std::shared_ptr< base::Blob< float > > brvis_blob
std::shared_ptr< base::Blob< float > > det3_ori_blob
std::shared_ptr< base::Blob< float > > det1_ori_blob
std::shared_ptr< base::Blob< float > > det1_obj_blob
std::shared_ptr< base::Blob< float > > rtvis_blob
std::shared_ptr< base::Blob< float > > det2_ori_conf_blob
std::shared_ptr< base::Blob< float > > cut_off_ratio_blob
std::shared_ptr< base::Blob< float > > det2_cls_blob
std::shared_ptr< base::Blob< float > > det2_dim_blob
std::shared_ptr< base::Blob< float > > det2_loc_blob
std::shared_ptr< base::Blob< float > > rtswt_blob
optional MinDims min_dims
optional float confidence_threshold
optional float cropped_ratio
optional int32 resized_width
optional float light_swt_conf_threshold
optional int32 aligned_pixel
optional common::ModelInfo info
optional float offset_ratio
optional float light_vis_conf_threshold
optional float border_ratio
optional NMSParam nms_param
std::vector< base::ObjectPtr > detected_objects
std::shared_ptr< base::Blob< float > > feature_blob
std::shared_ptr< camera::DataProvider > data_provider