-
Notifications
You must be signed in to change notification settings - Fork 4
/
GIEFeatExtractor.h
94 lines (69 loc) · 2.42 KB
/
GIEFeatExtractor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef GIEFEATEXTRACTOR_H_
#define GIEFEATEXTRACTOR_H_
#include <string>
#include <math.h>
// OpenCV
#include <opencv2/opencv.hpp>
// CUDA-C includes
#include <cuda.h>
#include <cuda_runtime.h>
// GIE
#include "NvInfer.h"
#include "NvCaffeParser.h"
#include "cudaUtility.h"
using namespace cv;
// Logger for GIE info/warning/errors
class Logger : public nvinfer1::ILogger
{
void log( Severity severity, const char* msg ) override
{
if( severity != Severity::kINFO )
std::cout << msg << std::endl;
}
};
class GIEFeatExtractor {
protected:
bool cudaFreeMapped(void *cpuPtr);
bool cudaAllocMapped( void** cpuPtr, void** gpuPtr, size_t size );
bool caffeToGIEModel( const std::string& deployFile, // name for caffe prototxt
const std::string& modelFile, // name for model
const std::string& binaryprotoFile, // name for .binaryproto
const std::vector<std::string>& outputs, // network outputs
unsigned int maxBatchSize, // batch size - NB must be at least as large as the batch we want to run with)
std::ostream& gieModelStream); // output stream for the GIE model
bool init(string _caffemodel_file,
string _binaryproto_meanfile, float meanR, float meanG, float meanB,
string _prototxt_file, int _resizeWidth, int _resizeHeight,
string _blob_name);
nvinfer1::IRuntime* mInfer;
nvinfer1::ICudaEngine* mEngine;
nvinfer1::IExecutionContext* mContext;
//cv::Mat meanMat;
float *meanData;
vector<float> mean_values;
nvinfer1::Dims4 resizeDims;
uint32_t mWidth;
uint32_t mHeight;
uint32_t mInputSize;
float* mInputCPU;
float* mInputCUDA;
uint32_t mOutputSize;
uint32_t mOutputDims;
float* mOutputCPU;
float* mOutputCUDA;
Logger gLogger;
public:
string prototxt_file;
string caffemodel_file;
string blob_name;
string binaryproto_meanfile;
bool timing;
GIEFeatExtractor(string _caffemodel_file,
string _binaryproto_meanfile, float _meanR, float _meanG, float _meanB,
string _prototxt_file, int _resizeWidth, int _resizeHeight,
string _blob_name,
bool _timing );
~GIEFeatExtractor();
bool extract_singleFeat_1D(cv::Mat &image, vector<float> &features, float (×)[2]);
};
#endif /* GIEFEATEXTRACTOR_H_ */