tensorRT serialization OK
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ public:
|
||||
dnnType *output;
|
||||
cudaStream_t stream;
|
||||
|
||||
NetworkRT(Network *net);
|
||||
NetworkRT(Network *net, const char *name);
|
||||
virtual ~NetworkRT();
|
||||
|
||||
/**
|
||||
|
||||
+35
-8
@@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <errno.h>
|
||||
|
||||
#include "NvInfer.h"
|
||||
|
||||
#include "NetworkRT.h"
|
||||
@@ -22,7 +24,7 @@ namespace tkDNN {
|
||||
|
||||
std::map<Layer*, nvinfer1::ITensor*>tensors;
|
||||
|
||||
NetworkRT::NetworkRT(Network *net) {
|
||||
NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
|
||||
float rt_ver = float(NV_TENSORRT_MAJOR) +
|
||||
float(NV_TENSORRT_MINOR)/10 +
|
||||
@@ -35,7 +37,7 @@ NetworkRT::NetworkRT(Network *net) {
|
||||
|
||||
//add input layer
|
||||
dataDim_t dim = net->layers[0]->input_dim;
|
||||
if(!fileExist("net.rt")) {
|
||||
if(!fileExist(name)) {
|
||||
ITensor *input = networkRT->addInput("data", dtRT,
|
||||
DimsCHW{ dim.c, dim.h, dim.w});
|
||||
checkNULL(input);
|
||||
@@ -64,9 +66,9 @@ NetworkRT::NetworkRT(Network *net) {
|
||||
engineRT = builderRT->buildCudaEngine(*networkRT);
|
||||
// we don't need the network any more
|
||||
//networkRT->destroy();
|
||||
serialize("net.rt");
|
||||
serialize(name);
|
||||
} else {
|
||||
deserialize("net.rt");
|
||||
deserialize(name);
|
||||
}
|
||||
|
||||
std::cout<<"create execution context\n";
|
||||
@@ -220,11 +222,16 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) {
|
||||
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
|
||||
IActivationLayer *lRT = networkRT->addActivation(*input, ActivationType::kRELU);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
} else if(l->act_mode == CUDNN_ACTIVATION_RELU) {
|
||||
IActivationLayer *lRT = networkRT->addActivation(*input, ActivationType::kRELU);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
|
||||
} else {
|
||||
FatalError("this Activation mode is not yet implemented");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ILayer* NetworkRT::convert_layer(ITensor *input, Softmax *l) {
|
||||
@@ -297,7 +304,27 @@ public:
|
||||
ActivationLeakyRT *a = new ActivationLeakyRT();
|
||||
a->size = readBUF<int>(buf);
|
||||
return a;
|
||||
}
|
||||
|
||||
if(name.find("Region") == 0) {
|
||||
RegionRT *r = new RegionRT(readBUF<int>(buf), //classes
|
||||
readBUF<int>(buf), //coords
|
||||
readBUF<int>(buf), //num
|
||||
readBUF<float>(buf)); //thesh
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
return r;
|
||||
}
|
||||
|
||||
if(name.find("Reorg") == 0) {
|
||||
ReorgRT *r = new ReorgRT(readBUF<int>(buf)); //stride
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
return r;
|
||||
}
|
||||
|
||||
FatalError("Cant deserialize Plugin");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -70,10 +70,18 @@ public:
|
||||
|
||||
|
||||
virtual size_t getSerializationSize() override {
|
||||
return 0;
|
||||
return 6*sizeof(int) + 1*sizeof(float);
|
||||
}
|
||||
|
||||
virtual void serialize(void* buffer) override {
|
||||
char *buf = reinterpret_cast<char*>(buffer);
|
||||
tkDNN::writeBUF(buf, classes);
|
||||
tkDNN::writeBUF(buf, coords);
|
||||
tkDNN::writeBUF(buf, num);
|
||||
tkDNN::writeBUF(buf, thresh);
|
||||
tkDNN::writeBUF(buf, c);
|
||||
tkDNN::writeBUF(buf, h);
|
||||
tkDNN::writeBUF(buf, w);
|
||||
}
|
||||
|
||||
int c, h, w;
|
||||
|
||||
@@ -48,10 +48,15 @@ public:
|
||||
|
||||
|
||||
virtual size_t getSerializationSize() override {
|
||||
return 0;
|
||||
return 4*sizeof(int);
|
||||
}
|
||||
|
||||
virtual void serialize(void* buffer) override {
|
||||
char *buf = reinterpret_cast<char*>(buffer);
|
||||
tkDNN::writeBUF(buf, stride);
|
||||
tkDNN::writeBUF(buf, c);
|
||||
tkDNN::writeBUF(buf, h);
|
||||
tkDNN::writeBUF(buf, w);
|
||||
}
|
||||
|
||||
int c, h, w, stride;
|
||||
|
||||
@@ -22,7 +22,7 @@ int main() {
|
||||
tkDNN::Dense l6(&net, 10, d3_bin);
|
||||
tkDNN::Softmax l7(&net);
|
||||
|
||||
tkDNN::NetworkRT netRT(&net);
|
||||
tkDNN::NetworkRT netRT(&net, "mnist.rt");
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
|
||||
@@ -60,7 +60,7 @@ int main() {
|
||||
net.print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tkDNN::NetworkRT netRT(&net);
|
||||
tkDNN::NetworkRT netRT(&net, "yolo-tiny.rt");
|
||||
|
||||
dnnType *out_data, *out_data2; // cudnn output, tensorRT output
|
||||
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ int main() {
|
||||
net.print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tkDNN::NetworkRT netRT(&net);
|
||||
tkDNN::NetworkRT netRT(&net, "yolo.rt");
|
||||
|
||||
dnnType *out_data, *out_data2; // cudnn output, tensorRT output
|
||||
|
||||
|
||||
Reference in New Issue
Block a user