Apollo  6.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 "modules/perception/camera/proto/yolo.pb.h"
24 
25 #include "cyber/common/file.h"
35 
36 namespace apollo {
37 namespace perception {
38 namespace camera {
39 
41  public:
44  if (stream_ != nullptr) {
45  cudaStreamDestroy(stream_);
46  }
47  }
48 
49  bool Init(const ObstacleDetectorInitOptions &options =
50  ObstacleDetectorInitOptions()) override;
51 
52  bool Detect(const ObstacleDetectorOptions &options,
53  CameraFrame *frame) override;
54  std::string Name() const override { return "YoloObstacleDetector"; }
55 
56  protected:
57  void LoadInputShape(const yolo::ModelParam &model_param);
58  void LoadParam(const yolo::YoloParam &yolo_param);
59  bool InitNet(const yolo::YoloParam &yolo_param,
60  const std::string &model_root);
61  void InitYoloBlob(const yolo::NetworkParam &net_param);
62  bool InitFeatureExtractor(const std::string &root_dir);
63 
64  private:
65  std::shared_ptr<BaseFeatureExtractor> feature_extractor_;
66  yolo::YoloParam yolo_param_;
67  std::shared_ptr<base::BaseCameraModel> base_camera_model_ = nullptr;
68  std::shared_ptr<inference::Inference> inference_;
69  std::vector<base::ObjectSubType> types_;
70  std::vector<float> expands_;
71  std::vector<float> anchors_;
72 
73  NMSParam nms_;
74  cudaStream_t stream_ = nullptr;
75  int height_ = 0;
76  int width_ = 0;
77  int offset_y_ = 0;
78  int gpu_id_ = 0;
79  int obj_k_ = kMaxObjSize;
80 
81  int ori_cycle_ = 1;
82  float confidence_threshold_ = 0.f;
83  float light_vis_conf_threshold_ = 0.f;
84  float light_swt_conf_threshold_ = 0.f;
85  MinDims min_dims_;
86  YoloBlobs yolo_blobs_;
87 
88  std::shared_ptr<base::Image8U> image_ = nullptr;
89  std::shared_ptr<base::Blob<bool>> overlapped_ = nullptr;
90  std::shared_ptr<base::Blob<int>> idx_sm_ = nullptr;
91 
92  bool with_box3d_ = false;
93  bool with_frbox_ = false;
94  bool with_lights_ = false;
95  bool with_ratios_ = false;
96  bool with_area_id_ = false;
97  float border_ratio_ = 0.f;
98 };
99 
100 } // namespace camera
101 } // namespace perception
102 } // namespace apollo
void LoadInputShape(const yolo::ModelParam &model_param)
void LoadParam(const yolo::YoloParam &yolo_param)
Definition: camera_frame.h:33
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: base_obstacle_detector.h:37
Definition: region_output.h:71
Definition: region_output.h:114
Definition: base_obstacle_detector.h:39
void InitYoloBlob(const yolo::NetworkParam &net_param)
bool Init(const ObstacleDetectorInitOptions &options=ObstacleDetectorInitOptions()) override
YoloObstacleDetector()
Definition: yolo_obstacle_detector.h:42
std::string Name() const override
Definition: yolo_obstacle_detector.h:54
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:43
Definition: base_obstacle_detector.h:30
Definition: region_output.h:78
bool Detect(const ObstacleDetectorOptions &options, CameraFrame *frame) override
Definition: yolo_obstacle_detector.h:40