himrep
GIEFeatExtractor.h
1 #ifndef GIEFEATEXTRACTOR_H_
2 #define GIEFEATEXTRACTOR_H_
3 
4 #include <string>
5 #include <math.h>
6 
7 // OpenCV
8 #include <opencv2/opencv.hpp>
9 
10 // CUDA-C includes
11 #include <cuda.h>
12 #include <cuda_runtime.h>
13 
14 // GIE
15 #include "NvInfer.h"
16 #include "NvCaffeParser.h"
17 #include "cudaUtility.h"
18 
19 using namespace cv;
20 
21 // Logger for GIE info/warning/errors
22 class Logger : public nvinfer1::ILogger
23 {
24  void log( Severity severity, const char* msg ) override
25  {
26  if( severity != Severity::kINFO )
27  std::cout << msg << std::endl;
28  }
29 };
30 
31 class GIEFeatExtractor {
32 
33 protected:
34 
35  bool cudaFreeMapped(void *cpuPtr);
36 
37  bool cudaAllocMapped( void** cpuPtr, void** gpuPtr, size_t size );
38 
39  bool caffeToGIEModel( const std::string& deployFile, // name for caffe prototxt
40  const std::string& modelFile, // name for model
41  const std::string& binaryprotoFile, // name for .binaryproto
42  const std::vector<std::string>& outputs, // network outputs
43  unsigned int maxBatchSize, // batch size - NB must be at least as large as the batch we want to run with)
44  std::ostream& gieModelStream); // output stream for the GIE model
45 
46  bool init(string _caffemodel_file,
47  string _binaryproto_meanfile, float meanR, float meanG, float meanB,
48  string _prototxt_file, int _resizeWidth, int _resizeHeight,
49  string _blob_name);
50 
51  nvinfer1::IRuntime* mInfer;
52  nvinfer1::ICudaEngine* mEngine;
53  nvinfer1::IExecutionContext* mContext;
54 
55  //cv::Mat meanMat;
56  float *meanData;
57  vector<float> mean_values;
58 
59  nvinfer1::Dims4 resizeDims;
60 
61  uint32_t mWidth;
62  uint32_t mHeight;
63  uint32_t mInputSize;
64  float* mInputCPU;
65  float* mInputCUDA;
66 
67  uint32_t mOutputSize;
68  uint32_t mOutputDims;
69  float* mOutputCPU;
70  float* mOutputCUDA;
71 
72  Logger gLogger;
73 
74 public:
75 
76  string prototxt_file;
77  string caffemodel_file;
78  string blob_name;
79  string binaryproto_meanfile;
80 
81  bool timing;
82 
83  GIEFeatExtractor(string _caffemodel_file,
84  string _binaryproto_meanfile, float _meanR, float _meanG, float _meanB,
85  string _prototxt_file, int _resizeWidth, int _resizeHeight,
86  string _blob_name,
87  bool _timing );
88 
89  ~GIEFeatExtractor();
90 
91  bool extract_singleFeat_1D(cv::Mat &image, vector<float> &features, float (&times)[2]);
92 };
93 
94 #endif /* GIEFEATEXTRACTOR_H_ */