Apollo 11.0
自动驾驶开放平台
yolox3d_obstacle_detector.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 <algorithm>
19#include <map>
20#include <memory>
21#include <string>
22#include <utility>
23#include <vector>
24
25#include <opencv2/imgproc.hpp>
26#include <opencv2/opencv.hpp>
27
28#include "modules/perception/camera_detection_multi_stage/detector/yolox3d/proto/model_param.pb.h"
29
34
35namespace apollo {
36namespace perception {
37namespace camera {
38
40public:
43 if (stream_ != nullptr) {
44 cudaStreamDestroy(stream_);
45 }
46 }
47
54 bool Init(const ObstacleDetectorInitOptions &options = ObstacleDetectorInitOptions()) override;
55
56 bool Detect(onboard::CameraFrame *frame) override;
57
63 std::string Name() const override {
64 return "Yolox3DObstacleDetector";
65 }
66
67protected:
75 bool Preprocess(const base::Image8U *image, base::BlobPtr<float> input_blob);
76
83 void LoadInputShape(const yolox3d::ModelParam &model_param);
84
91 void LoadParam(const yolox3d::ModelParam &model_param);
98 void Yolo3DInference(const base::Image8U *image, std::vector<base::ObjectPtr> &detect_objs);
107 bool Init3DNetwork(const common::ModelInfo &model_info, const std::string &model_path);
108
109private:
111 yolox3d::ModelParam model_param_;
113
114 std::shared_ptr<inference::Inference> net_3D_;
115 FILE *file_;
116
117 int gpu_id_ = 0;
118 int max_batch_size_ = 32;
119 cudaStream_t stream_ = nullptr;
120
121 // yolo input image size
122 int width_ = 0;
123 int height_ = 0;
124 // image size of raw image
125 int image_width_ = 0;
126 int image_height_ = 0;
127 float confidence_threshold_ = 0.f;
128
129 float border_ratio_ = 0.f;
130 cv::Mat img_;
131};
132
133} // namespace camera
134} // namespace perception
135} // namespace apollo
A wrapper around Blob holders serving as the basic computational unit for images.
Definition image_8u.h:44
bool Init(const ObstacleDetectorInitOptions &options=ObstacleDetectorInitOptions()) override
Necessary, Init yolox3d model params normal, but now use pipline instead
std::string Name() const override
return detector name
bool Detect(onboard::CameraFrame *frame) override
Interface for obstacle detector main part
bool Init3DNetwork(const common::ModelInfo &model_info, const std::string &model_path)
Init model inference
void LoadInputShape(const yolox3d::ModelParam &model_param)
Resize model input picture size according to the config file
void Yolo3DInference(const base::Image8U *image, std::vector< base::ObjectPtr > &detect_objs)
Load yolo3D libtorch model params from model file
void LoadParam(const yolox3d::ModelParam &model_param)
Load yolo libtorch model params from model file
bool Preprocess(const base::Image8U *image, base::BlobPtr< float > input_blob)
Preprocess of image before inference, resize input data blob and fill image data to blob
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition blob.h:313
class register implement
Definition arena_queue.h:37