-
Notifications
You must be signed in to change notification settings - Fork 0
/
retinaface.h
62 lines (52 loc) · 2.36 KB
/
retinaface.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
#include <fstream>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
#include <chrono>
#include "cuda_runtime_api.h"
#include "logging.h"
#include "common.hpp"
#include "calibrator.h"
#include "opencv2/opencv.hpp"
#define CHECK(status) \
do\
{\
auto ret = (status);\
if (ret != 0)\
{\
std::cerr << "Cuda failure: " << ret << std::endl;\
abort();\
}\
} while (0)
//#define USE_FP16 // comment out this if want to use FP32
#define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32
#define DEVICE 0 // GPU id
#define BATCH_SIZE 1
#define CONF_THRESH 0.75
#define IOU_THRESH 0.4
using namespace nvinfer1;
class retinaface {
public:
retinaface();
~retinaface();
int WTSToEngine(std::string wtsfile,std::string enginefile);
int Init(std::string enginefile);
void UnInit();
bool Inference_file(std::string imagefile,cv::Mat& face,cv::Mat& result,bool is_build_lib=false);
ICudaEngine* createEngine(const std::string wtsfile,unsigned int maxBatchSize, IBuilder* builder, IBuilderConfig* config, DataType dt);
// void APIToModel(const std::string wtsfile,unsigned int maxBatchSize, IHostMemory** modelStream);
void doInference(IExecutionContext& context, float* input, float* output, int batchSize);
private:
IExecutionContext* context;
ICudaEngine* engine;
IRuntime* runtime;
ILayer* conv_bn(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, std::string lname, int oup, int s, float leaky);
ILayer* conv_bn_no_relu(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, std::string lname, int oup, int s);
ILayer* conv_bn1X1(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, std::string lname, int oup, int s, float leaky ) ;
ILayer* conv_dw(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, std::string lname, int inp, int oup, int s, float leaky);
IActivationLayer* ssh(INetworkDefinition *network, std::map<std::string, Weights>& weightMap, ITensor& input, std::string lname, int oup);
ICudaEngine* createEngine(unsigned int maxBatchSize, IBuilder* builder, IBuilderConfig* config, DataType dt);
// stuff we know about the network and the input/output blobs
Logger gLogger;
};