-
Notifications
You must be signed in to change notification settings - Fork 7
/
Detector.h
64 lines (52 loc) · 1.52 KB
/
Detector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <algorithm>
#include <numeric>
#include <opencv2/opencv.hpp>
#include "NvInfer.h"
#include "NvOnnxParser.h"
#include "Utils.h"
#include "EntropyCalibrator.h"
//#define PROFILE
static const int INPUT_CHANNEL = 3;
static const int CHECK_COUNT = 3;
static const int BATCH_SIZE = 2;
struct YoloKernel
{
int width;
int height;
float anchors[CHECK_COUNT * 2];
};
struct Detection{
float bbox[4];
int classId;
float prob;
};
class Detector
{
public:
Detector(std::string onnxFile, std::string trtFile, std::string calibFileList, int input_w, int input_h, int num_classes, float yolo_thresh, float nms_thresh, bool use_int8);
~Detector();
std::vector<std::vector<Detection>> doInference(std::vector<cv::Mat>& imgs);
private:
void postProcessImg(cv::Mat& img, std::vector<Detection>& detections);
void doNms(std::vector<Detection>& detections, float nmsThresh);
std::vector<std::vector<Detection>> interpretOutputTensor(float *tensor, int batchSize);
Logger logger_;
Profiler profiler_;
nvinfer1::IExecutionContext* context_;
nvinfer1::ICudaEngine* engine_;
nvinfer1::IRuntime* runtime_;
std::unique_ptr<float[]> inputData_;
std::unique_ptr<float[]> outputData_;
cudaStream_t stream_;
std::unique_ptr<void*[]> buffers_;
std::vector<YoloKernel> yoloKernel_;
int inputW_;
int inputH_;
int numClasses_;
float yoloThresh_;
float nmsThresh_;
const YoloKernel yolo1_;
const YoloKernel yolo2_;
const YoloKernel yolo3_;
};