Apollo  v5.5.0
Open source self driving car software
yolo_obstacle_detector.h
Go to the documentation of this file.
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 #pragma once
17 
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "cyber/common/file.h"
29 #include "modules/perception/camera/lib/obstacle/detector/yolo/proto/yolo.pb.h"
34 
35 namespace apollo {
36 namespace perception {
37 namespace camera {
38 
40  public:
43  if (stream_ != nullptr) {
44  cudaStreamDestroy(stream_);
45  }
46  }
47 
48  bool Init(const ObstacleDetectorInitOptions &options =
49  ObstacleDetectorInitOptions()) override;
50 
51  bool Detect(const ObstacleDetectorOptions &options,
52  CameraFrame *frame) override;
53  std::string Name() const override { return "YoloObstacleDetector"; }
54 
55  protected:
56  void LoadInputShape(const yolo::ModelParam &model_param);
57  void LoadParam(const yolo::YoloParam &yolo_param);
58  bool InitNet(const yolo::YoloParam &yolo_param,
59  const std::string &model_root);
60  void InitYoloBlob(const yolo::NetworkParam &net_param);
61  bool InitFeatureExtractor(const std::string &root_dir);
62 
63  private:
64  std::shared_ptr<BaseFeatureExtractor> feature_extractor_;
65  yolo::YoloParam yolo_param_;
66  std::shared_ptr<base::BaseCameraModel> base_camera_model_ = nullptr;
67  std::shared_ptr<inference::Inference> inference_;
68  std::vector<base::ObjectSubType> types_;
69  std::vector<float> expands_;
70  std::vector<float> anchors_;
71 
72  NMSParam nms_;
73  cudaStream_t stream_ = nullptr;
74  int height_ = 0;
75  int width_ = 0;
76  int offset_y_ = 0;
77  int gpu_id_ = 0;
78  int obj_k_ = kMaxObjSize;
79 
80  int ori_cycle_ = 1;
81  float confidence_threshold_ = 0.f;
82  float light_vis_conf_threshold_ = 0.f;
83  float light_swt_conf_threshold_ = 0.f;
84  MinDims min_dims_;
85  YoloBlobs yolo_blobs_;
86 
87  std::shared_ptr<base::Image8U> image_ = nullptr;
88  std::shared_ptr<base::Blob<bool>> overlapped_ = nullptr;
89  std::shared_ptr<base::Blob<int>> idx_sm_ = nullptr;
90 
91  bool with_box3d_ = false;
92  bool with_frbox_ = false;
93  bool with_lights_ = false;
94  bool with_ratios_ = false;
95  bool with_area_id_ = false;
96  float border_ratio_ = 0.f;
97 };
98 
99 } // namespace camera
100 } // namespace perception
101 } // namespace apollo
void LoadInputShape(const yolo::ModelParam &model_param)
void LoadParam(const yolo::YoloParam &yolo_param)
Definition: camera_frame.h:33
Definition: blob.h:72
Definition: base_obstacle_detector.h:35
Definition: region_output.h:69
Definition: region_output.h:112
Definition: base_obstacle_detector.h:37
void InitYoloBlob(const yolo::NetworkParam &net_param)
bool Init(const ObstacleDetectorInitOptions &options=ObstacleDetectorInitOptions()) override
YoloObstacleDetector()
Definition: yolo_obstacle_detector.h:41
std::string Name() const override
Definition: yolo_obstacle_detector.h:53
bool InitFeatureExtractor(const std::string &root_dir)
bool InitNet(const yolo::YoloParam &yolo_param, const std::string &model_root)
virtual ~YoloObstacleDetector()
Definition: yolo_obstacle_detector.h:42
Definition: base_obstacle_detector.h:30
Definition: region_output.h:76
bool Detect(const ObstacleDetectorOptions &options, CameraFrame *frame) override
Definition: yolo_obstacle_detector.h:39