forked from Ghustwb/MobileNet-SSD-TensorRT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tensorNet.h
executable file
·87 lines (66 loc) · 2.29 KB
/
tensorNet.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
#include "pluginImplement.h"
using namespace nvinfer1;
using namespace nvcaffeparser1;
/******************************/
// TensorRT utility
/******************************/
class Logger : public ILogger
{
void log(Severity severity, const char* msg) override
{
if (severity!=Severity::kINFO) std::cout << msg << std::endl;
}
};
struct Profiler : public IProfiler
{
typedef std::pair<std::string, float> Record;
std::vector<Record> mProfile;
virtual void reportLayerTime(const char* layerName, float ms)
{
auto record = std::find_if(mProfile.begin(), mProfile.end(), [&](const Record& r){ return r.first == layerName; });
if (record == mProfile.end()) mProfile.push_back(std::make_pair(layerName, ms));
else record->second += ms;
}
void printLayerTimes(const int TIMING_ITERATIONS)
{
float totalTime = 0;
for (size_t i = 0; i < mProfile.size(); i++)
{
printf("%-40.40s %4.3fms\n", mProfile[i].first.c_str(), mProfile[i].second / TIMING_ITERATIONS);
totalTime += mProfile[i].second;
}
printf("Time over all layers: %4.3f\n", totalTime / TIMING_ITERATIONS);
}
};
/******************************/
// TensorRT Main
/******************************/
class TensorNet
{
public:
bool caffeToTRTModel(const char* deployFile,
const char* modelFile,
const std::vector<std::string>& outputs,
unsigned int maxBatchSize,
std::ostream& gieModelStream);
bool LoadNetwork( const char* prototxt_path,
const char* model_path,
const char* input_blob,
const std::vector<std::string>& output_blobs,
uint32_t maxBatchSize );
void createInference();
void imageInference(void** buffers, int nbBuffer, int batchSize);
void timeInference(int iteration, int batchSize);
DimsCHW getTensorDims(const char* name);
// void getLayerOutput(const char* name);
void printTimes(int iteration);
void destroy();
private:
PluginFactory pluginFactory;
IHostMemory *gieModelStream{nullptr};
IRuntime* infer;
ICudaEngine* engine;
Logger gLogger;
Profiler gProfiler;
};
//#endif