Merge remote-tracking branch 'origin/master' into cnet
This commit is contained in:
@@ -479,6 +479,18 @@ int main()
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// for(int i=0; i<net.num_layers; i++) {
|
||||
// if(net.layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net.layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net.layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net.layers[i]->dstData);
|
||||
// net.layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("dla34_cnet"));
|
||||
|
||||
|
||||
@@ -353,6 +353,18 @@ int main()
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// for(int i=0; i<net.num_layers; i++) {
|
||||
// if(net.layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net.layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net.layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net.layers[i]->dstData);
|
||||
// net.layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("resnet101_cnet"));
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,281 @@
|
||||
[net]
|
||||
# Testing
|
||||
#batch=1
|
||||
#subdivisions=1
|
||||
# Training
|
||||
batch=64
|
||||
subdivisions=1
|
||||
width=512
|
||||
height=512
|
||||
channels=3
|
||||
momentum=0.9
|
||||
decay=0.0005
|
||||
angle=0
|
||||
saturation = 1.5
|
||||
exposure = 1.5
|
||||
hue=.1
|
||||
|
||||
learning_rate=0.00261
|
||||
burn_in=1000
|
||||
max_batches = 500200
|
||||
policy=steps
|
||||
steps=400000,450000
|
||||
scales=.1,.1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=32
|
||||
size=3
|
||||
stride=2
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=2
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers=-1
|
||||
groups=2
|
||||
group_id=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=32
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=32
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -1,-2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -6,-1
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers=-1
|
||||
groups=2
|
||||
group_id=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -1,-2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -6,-1
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers=-1
|
||||
groups=2
|
||||
group_id=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -1,-2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -6,-1
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
##################################
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
|
||||
|
||||
[yolo]
|
||||
mask = 3,4,5
|
||||
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
|
||||
classes=80
|
||||
num=6
|
||||
jitter=.3
|
||||
scale_x_y = 1.05
|
||||
cls_normalizer=1.0
|
||||
iou_normalizer=0.07
|
||||
iou_loss=ciou
|
||||
ignore_thresh = .7
|
||||
truth_thresh = 1
|
||||
random=0
|
||||
resize=1.5
|
||||
nms_kind=greedynms
|
||||
beta_nms=0.6
|
||||
|
||||
[route]
|
||||
layers = -4
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[upsample]
|
||||
stride=2
|
||||
|
||||
[route]
|
||||
layers = -1, 23
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
[yolo]
|
||||
mask = 1,2,3
|
||||
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
|
||||
classes=80
|
||||
num=6
|
||||
jitter=.3
|
||||
scale_x_y = 1.05
|
||||
cls_normalizer=1.0
|
||||
iou_normalizer=0.07
|
||||
iou_loss=ciou
|
||||
ignore_thresh = .7
|
||||
truth_thresh = 1
|
||||
random=0
|
||||
resize=1.5
|
||||
nms_kind=greedynms
|
||||
beta_nms=0.6
|
||||
@@ -0,0 +1,2 @@
|
||||
person
|
||||
stop sign
|
||||
@@ -23,6 +23,18 @@ int main() {
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
// for(int i=0; i<net->num_layers; i++) {
|
||||
// if(net->layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net->layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net->layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net->layers[i]->dstData);
|
||||
// net->layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
|
||||
@@ -22,6 +22,19 @@ int main() {
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
// for(int i=0; i<net->num_layers; i++) {
|
||||
// if(net->layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net->layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net->layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net->layers[i]->dstData);
|
||||
// net->layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ int main() {
|
||||
bin_path + "/debug/layer161_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4.cfg";
|
||||
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download");
|
||||
std::string cfg_path = "../tests/darknet/cfg/yolo4.cfg";
|
||||
std::string name_path = "../tests/darknet/names/coco.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/982LxTQcNQfFQc4/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4_320";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer139_out.bin",
|
||||
bin_path + "/debug/layer150_out.bin",
|
||||
bin_path + "/debug/layer161_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = "../tests/darknet/cfg/yolo4_320.cfg";
|
||||
std::string name_path = "../tests/darknet/names/coco.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/64PHAwrM6RCZbiR/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4_320_coco2";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer139_out.bin",
|
||||
bin_path + "/debug/layer150_out.bin",
|
||||
bin_path + "/debug/layer161_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = "../tests/darknet/cfg/yolo4_320_coco2.cfg";
|
||||
std::string name_path = "../tests/darknet/names/coco2.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/f3wk99iG5y7tEr8/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4_512";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer139_out.bin",
|
||||
bin_path + "/debug/layer150_out.bin",
|
||||
bin_path + "/debug/layer161_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = "../tests/darknet/cfg/yolo4_512.cfg";
|
||||
std::string name_path = "../tests/darknet/names/coco.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/fjFDqFmiSARKxFe/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
// for(int i=0; i<net->num_layers; i++) {
|
||||
// if(net->layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net->layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net->layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net->layers[i]->dstData);
|
||||
// net->layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4_608";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer139_out.bin",
|
||||
bin_path + "/debug/layer150_out.bin",
|
||||
bin_path + "/debug/layer161_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = "../tests/darknet/cfg/yolo4_608.cfg";
|
||||
std::string name_path = "../tests/darknet/names/coco.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/Bg9r7kqDFJiFB4c/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4_berkeley_f1";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer139_out.bin",
|
||||
bin_path + "/debug/layer150_out.bin",
|
||||
bin_path + "/debug/layer161_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4_berkeley.cfg";
|
||||
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/M7WJdGoGDaDACnN/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4tiny_512";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer30_out.bin",
|
||||
bin_path + "/debug/layer37_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4tiny_512.cfg";
|
||||
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/qa2ws4GXg7mS5nN/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
// for(int i=0; i<net->num_layers; i++) {
|
||||
// if(net->layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net->layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net->layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net->layers[i]->dstData);
|
||||
// net->layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -469,6 +469,19 @@ int main()
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// for(int i=0; i<net.num_layers; i++) {
|
||||
// if(net.layers[i]->getLayerType() == tk::dnn::LAYER_CONV2D) {
|
||||
// tk::dnn::Conv2d *c = (tk::dnn::Conv2d*) net.layers[i];
|
||||
// c->releaseDevice();
|
||||
// c->releaseHost(true, false);
|
||||
// }
|
||||
// if(net.layers[i]->dstData != nullptr) {
|
||||
// cudaFree(net.layers[i]->dstData);
|
||||
// net.layers[i]->dstData = nullptr;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("mobilenetv2ssd512"));
|
||||
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "NetworkViz.h"
|
||||
|
||||
|
||||
const char *input_bin = "shelfnet/debug/input.bin";
|
||||
|
||||
const char *backbone[] = {
|
||||
"shelfnet/layers/backbone-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer1-0-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer1-0-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer1-1-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer1-1-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer2-0-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer2-0-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer2-0-downsample-0.bin",
|
||||
"shelfnet/layers/backbone-layer2-1-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer2-1-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer3-0-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer3-0-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer3-0-downsample-0.bin",
|
||||
"shelfnet/layers/backbone-layer3-1-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer3-1-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer4-0-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer4-0-conv2.bin",
|
||||
"shelfnet/layers/backbone-layer4-0-downsample-0.bin",
|
||||
"shelfnet/layers/backbone-layer4-1-conv1.bin",
|
||||
"shelfnet/layers/backbone-layer4-1-conv2.bin"};
|
||||
|
||||
const char *conv_out[] = {
|
||||
"shelfnet/layers/conv_out-conv-conv.bin",
|
||||
"shelfnet/layers/conv_out-conv_out.bin",
|
||||
"shelfnet/layers/conv_out16-conv-conv.bin",
|
||||
"shelfnet/layers/conv_out16-conv_out.bin",
|
||||
"shelfnet/layers/conv_out32-conv-conv.bin",
|
||||
"shelfnet/layers/conv_out32-conv_out.bin"
|
||||
};
|
||||
|
||||
const char *decoder[] = {
|
||||
"shelfnet/layers/decoder-bottom-conv1.bin",
|
||||
"shelfnet/layers/decoder-bottom-conv12.bin",
|
||||
"shelfnet/layers/decoder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet/layers/decoder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet/layers/decoder-up_dense_list-0-conv.bin",
|
||||
"shelfnet/layers/decoder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet/layers/decoder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet/layers/decoder-up_dense_list-1-conv.bin"
|
||||
};
|
||||
|
||||
|
||||
const char *ladder[] = {
|
||||
"shelfnet/layers/ladder-inconv-conv1.bin",
|
||||
"shelfnet/layers/ladder-inconv-conv12.bin",
|
||||
"shelfnet/layers/ladder-down_module_list-0-conv1.bin",
|
||||
"shelfnet/layers/ladder-down_module_list-0-conv12.bin",
|
||||
"shelfnet/layers/ladder-down_conv_list-0.bin",
|
||||
|
||||
"shelfnet/layers/ladder-down_module_list-1-conv1.bin",
|
||||
"shelfnet/layers/ladder-down_module_list-1-conv12.bin",
|
||||
"shelfnet/layers/ladder-down_conv_list-1.bin",
|
||||
|
||||
"shelfnet/layers/ladder-bottom-conv1.bin",
|
||||
"shelfnet/layers/ladder-bottom-conv12.bin",
|
||||
|
||||
|
||||
|
||||
"shelfnet/layers/ladder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet/layers/ladder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet/layers/ladder-up_dense_list-0-conv.bin",
|
||||
|
||||
|
||||
"shelfnet/layers/ladder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet/layers/ladder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet/layers/ladder-up_dense_list-1-conv.bin"};
|
||||
|
||||
const char *trans[] = {
|
||||
"shelfnet/layers/trans1-conv.bin",
|
||||
"shelfnet/layers/trans2-conv.bin",
|
||||
"shelfnet/layers/trans3-conv.bin"};
|
||||
int main()
|
||||
{
|
||||
|
||||
downloadWeightsifDoNotExist(input_bin, "shelfnet", "https://cloud.hipert.unimore.it/s/mEDZMRJaGCFWSJF/download");
|
||||
|
||||
int classes = 19;
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 3, 1024, 1024, 1);
|
||||
tk::dnn::Network net(dim);
|
||||
|
||||
int bi = 0, di = 0, li = 0, ci = 0;
|
||||
new tk::dnn::Conv2d(&net, 64, 7, 7, 2, 2, 3, 3, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* last = new tk::dnn::Pooling (&net, 3, 3, 2, 2, 1, 1, tk::dnn::POOLING_MAX);
|
||||
|
||||
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
}
|
||||
|
||||
std::vector<tk::dnn::Layer*> features;
|
||||
for(int i=0;i<3;++i){
|
||||
int out_channel = pow(2,7+i);
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 2, 2, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* bn2 = new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 2, 2, 0, 0, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, bn2);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
features.push_back(last);
|
||||
}
|
||||
|
||||
for(int i=0; i<features.size(); ++i){
|
||||
new tk::dnn::Route(&net, &features[i], 1);
|
||||
int out_channel = pow(2,6+i);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, trans[i], true);
|
||||
features[i] = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
}
|
||||
|
||||
//DECODER
|
||||
|
||||
last = features[2];
|
||||
std::vector<tk::dnn::Layer*> up_out;
|
||||
//bottom
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, decoder[di++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, features[1-i]);
|
||||
|
||||
//up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
//LADDER
|
||||
|
||||
std::vector<tk::dnn::Layer*> down_out;
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
for(int i=0; i<2;++i){
|
||||
int out_channel = pow(2,6+i);
|
||||
tk::dnn::Layer* l_last = new tk::dnn::Shortcut(&net, up_out[2-i]);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, l_last);
|
||||
l_last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
down_out.push_back(l_last);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel*2, 3, 3, 2, 2, 1, 1, ladder[li++], false);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.0f); //should be ReLU
|
||||
}
|
||||
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.clear();
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, ladder[li++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, down_out[1-i]);
|
||||
|
||||
// //up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
|
||||
// for(int i=2;i>=0;--i){
|
||||
// new tk::dnn::Route(&net, &up_out[i], 1);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, conv_out[ci++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 19, 3, 3, 1, 1, 1, 1, conv_out[ci++], false);
|
||||
/*up_out[i] =*/ new tk::dnn::Resize(&net, 19, net.input_dim.h, net.input_dim.w, true, tk::dnn::ResizeMode_t::LINEAR);
|
||||
// }
|
||||
|
||||
new tk::dnn::Softmax(&net);
|
||||
|
||||
const char *output_bin = "shelfnet/debug/softmax.bin";
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
|
||||
std::cout<<"Input:"<<std::endl;
|
||||
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// // convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("shelfnet"));
|
||||
|
||||
tk::dnn::dataDim_t dim1 = dim; //input dim
|
||||
dnnType *cudnn_out = nullptr;
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TKDNN_TSTART
|
||||
cudnn_out = net.infer(dim1, data);
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
tk::dnn::dataDim_t dim2 = dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
dnnType *rt_out1 = (dnnType *)netRT.buffersRT[1];
|
||||
|
||||
printCenteredTitle(std::string(" CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out1, *out1_h;
|
||||
int odim1 = dim1.tot();
|
||||
readBinaryFile(output_bin, odim1, &out1_h, &out1);
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
std::cout << "CUDNN vs correct" << std::endl;
|
||||
ret_cudnn |= checkResult(odim1, cudnn_out, out1, true, 20) == 0 ? 0 : ERROR_CUDNN;
|
||||
|
||||
std::cout << "TRT vs correct" << std::endl;
|
||||
ret_tensorrt |=checkResult(odim1, rt_out1, out1) == 0 ? 0 : ERROR_TENSORRT;
|
||||
|
||||
std::cout << "CUDNN vs TRT " << std::endl;
|
||||
ret_cudnn_tensorrt |= checkResult(odim1, cudnn_out, rt_out1) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
|
||||
cv::Mat viz = vizLayer2Mat(&net, net.num_layers-1);
|
||||
cv::imwrite("test.png", viz);
|
||||
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "NetworkViz.h"
|
||||
|
||||
|
||||
const char *input_bin = "shelfnet_berkeley/debug/input.bin";
|
||||
|
||||
const char *backbone[] = {
|
||||
"shelfnet_berkeley/layers/backbone-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer1-0-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer1-0-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer1-1-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer1-1-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer2-0-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer2-0-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer2-0-downsample-0.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer2-1-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer2-1-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer3-0-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer3-0-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer3-0-downsample-0.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer3-1-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer3-1-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer4-0-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer4-0-conv2.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer4-0-downsample-0.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer4-1-conv1.bin",
|
||||
"shelfnet_berkeley/layers/backbone-layer4-1-conv2.bin"};
|
||||
|
||||
const char *conv_out[] = {
|
||||
"shelfnet_berkeley/layers/conv_out-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/conv_out-conv_out.bin",
|
||||
"shelfnet_berkeley/layers/conv_out16-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/conv_out16-conv_out.bin",
|
||||
"shelfnet_berkeley/layers/conv_out32-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/conv_out32-conv_out.bin"
|
||||
};
|
||||
|
||||
const char *decoder[] = {
|
||||
"shelfnet_berkeley/layers/decoder-bottom-conv1.bin",
|
||||
"shelfnet_berkeley/layers/decoder-bottom-conv12.bin",
|
||||
"shelfnet_berkeley/layers/decoder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/decoder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet_berkeley/layers/decoder-up_dense_list-0-conv.bin",
|
||||
"shelfnet_berkeley/layers/decoder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/decoder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet_berkeley/layers/decoder-up_dense_list-1-conv.bin"
|
||||
};
|
||||
|
||||
|
||||
const char *ladder[] = {
|
||||
"shelfnet_berkeley/layers/ladder-inconv-conv1.bin",
|
||||
"shelfnet_berkeley/layers/ladder-inconv-conv12.bin",
|
||||
"shelfnet_berkeley/layers/ladder-down_module_list-0-conv1.bin",
|
||||
"shelfnet_berkeley/layers/ladder-down_module_list-0-conv12.bin",
|
||||
"shelfnet_berkeley/layers/ladder-down_conv_list-0.bin",
|
||||
|
||||
"shelfnet_berkeley/layers/ladder-down_module_list-1-conv1.bin",
|
||||
"shelfnet_berkeley/layers/ladder-down_module_list-1-conv12.bin",
|
||||
"shelfnet_berkeley/layers/ladder-down_conv_list-1.bin",
|
||||
|
||||
"shelfnet_berkeley/layers/ladder-bottom-conv1.bin",
|
||||
"shelfnet_berkeley/layers/ladder-bottom-conv12.bin",
|
||||
|
||||
|
||||
|
||||
"shelfnet_berkeley/layers/ladder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/ladder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet_berkeley/layers/ladder-up_dense_list-0-conv.bin",
|
||||
|
||||
|
||||
"shelfnet_berkeley/layers/ladder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet_berkeley/layers/ladder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet_berkeley/layers/ladder-up_dense_list-1-conv.bin"};
|
||||
|
||||
const char *trans[] = {
|
||||
"shelfnet_berkeley/layers/trans1-conv.bin",
|
||||
"shelfnet_berkeley/layers/trans2-conv.bin",
|
||||
"shelfnet_berkeley/layers/trans3-conv.bin"};
|
||||
int main()
|
||||
{
|
||||
|
||||
downloadWeightsifDoNotExist(input_bin, "shelfnet_berkeley", "https://cloud.hipert.unimore.it/s/m92e7QdD9gYMF7f/download");
|
||||
|
||||
int classes = 20;
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 3, 736, 1280, 1);
|
||||
tk::dnn::Network net(dim);
|
||||
|
||||
int bi = 0, di = 0, li = 0, ci = 0;
|
||||
new tk::dnn::Conv2d(&net, 64, 7, 7, 2, 2, 3, 3, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* last = new tk::dnn::Pooling (&net, 3, 3, 2, 2, 1, 1, tk::dnn::POOLING_MAX);
|
||||
|
||||
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
}
|
||||
|
||||
std::vector<tk::dnn::Layer*> features;
|
||||
for(int i=0;i<3;++i){
|
||||
int out_channel = pow(2,7+i);
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 2, 2, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* bn2 = new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 2, 2, 0, 0, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, bn2);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
features.push_back(last);
|
||||
}
|
||||
|
||||
for(int i=0; i<features.size(); ++i){
|
||||
new tk::dnn::Route(&net, &features[i], 1);
|
||||
int out_channel = pow(2,6+i);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, trans[i], true);
|
||||
features[i] = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
}
|
||||
|
||||
//DECODER
|
||||
|
||||
last = features[2];
|
||||
std::vector<tk::dnn::Layer*> up_out;
|
||||
//bottom
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, decoder[di++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, features[1-i]);
|
||||
|
||||
//up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
//LADDER
|
||||
|
||||
std::vector<tk::dnn::Layer*> down_out;
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
for(int i=0; i<2;++i){
|
||||
int out_channel = pow(2,6+i);
|
||||
tk::dnn::Layer* l_last = new tk::dnn::Shortcut(&net, up_out[2-i]);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, l_last);
|
||||
l_last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
down_out.push_back(l_last);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel*2, 3, 3, 2, 2, 1, 1, ladder[li++], false);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.0f); //should be ReLU
|
||||
}
|
||||
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.clear();
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, ladder[li++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, down_out[1-i]);
|
||||
|
||||
// //up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
|
||||
// for(int i=2;i>=0;--i){
|
||||
// new tk::dnn::Route(&net, &up_out[i], 1);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, conv_out[ci++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, classes, 3, 3, 1, 1, 1, 1, conv_out[ci++], false);
|
||||
/*up_out[i] =*/ new tk::dnn::Resize(&net, classes, net.input_dim.h, net.input_dim.w, true, tk::dnn::ResizeMode_t::LINEAR);
|
||||
// }
|
||||
|
||||
new tk::dnn::Softmax(&net);
|
||||
|
||||
const char *output_bin = "shelfnet_berkeley/debug/softmax.bin";
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
|
||||
std::cout<<"Input:"<<std::endl;
|
||||
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// // convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("shelfnet_berkeley"));
|
||||
|
||||
tk::dnn::dataDim_t dim1 = dim; //input dim
|
||||
dnnType *cudnn_out = nullptr;
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TKDNN_TSTART
|
||||
cudnn_out = net.infer(dim1, data);
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
tk::dnn::dataDim_t dim2 = dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
dnnType *rt_out1 = (dnnType *)netRT.buffersRT[1];
|
||||
|
||||
printCenteredTitle(std::string(" CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out1, *out1_h;
|
||||
int odim1 = dim1.tot();
|
||||
readBinaryFile(output_bin, odim1, &out1_h, &out1);
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
std::cout << "CUDNN vs correct" << std::endl;
|
||||
ret_cudnn |= checkResult(odim1, cudnn_out, out1, true, 20) == 0 ? 0 : ERROR_CUDNN;
|
||||
|
||||
std::cout << "TRT vs correct" << std::endl;
|
||||
ret_tensorrt |=checkResult(odim1, rt_out1, out1) == 0 ? 0 : ERROR_TENSORRT;
|
||||
|
||||
std::cout << "CUDNN vs TRT " << std::endl;
|
||||
ret_cudnn_tensorrt |= checkResult(odim1, cudnn_out, rt_out1) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
|
||||
cv::Mat viz = vizLayer2Mat(&net, net.num_layers-1);
|
||||
cv::imwrite("test.png", viz);
|
||||
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "NetworkViz.h"
|
||||
|
||||
|
||||
const char *input_bin = "shelfnet_mapillary/debug/input.bin";
|
||||
|
||||
const char *backbone[] = {
|
||||
"shelfnet_mapillary/layers/backbone-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer1-0-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer1-0-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer1-1-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer1-1-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer2-0-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer2-0-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer2-0-downsample-0.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer2-1-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer2-1-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer3-0-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer3-0-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer3-0-downsample-0.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer3-1-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer3-1-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer4-0-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer4-0-conv2.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer4-0-downsample-0.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer4-1-conv1.bin",
|
||||
"shelfnet_mapillary/layers/backbone-layer4-1-conv2.bin"};
|
||||
|
||||
const char *conv_out[] = {
|
||||
"shelfnet_mapillary/layers/conv_out-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/conv_out-conv_out.bin",
|
||||
"shelfnet_mapillary/layers/conv_out16-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/conv_out16-conv_out.bin",
|
||||
"shelfnet_mapillary/layers/conv_out32-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/conv_out32-conv_out.bin"
|
||||
};
|
||||
|
||||
const char *decoder[] = {
|
||||
"shelfnet_mapillary/layers/decoder-bottom-conv1.bin",
|
||||
"shelfnet_mapillary/layers/decoder-bottom-conv12.bin",
|
||||
"shelfnet_mapillary/layers/decoder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/decoder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet_mapillary/layers/decoder-up_dense_list-0-conv.bin",
|
||||
"shelfnet_mapillary/layers/decoder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/decoder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet_mapillary/layers/decoder-up_dense_list-1-conv.bin"
|
||||
};
|
||||
|
||||
|
||||
const char *ladder[] = {
|
||||
"shelfnet_mapillary/layers/ladder-inconv-conv1.bin",
|
||||
"shelfnet_mapillary/layers/ladder-inconv-conv12.bin",
|
||||
"shelfnet_mapillary/layers/ladder-down_module_list-0-conv1.bin",
|
||||
"shelfnet_mapillary/layers/ladder-down_module_list-0-conv12.bin",
|
||||
"shelfnet_mapillary/layers/ladder-down_conv_list-0.bin",
|
||||
|
||||
"shelfnet_mapillary/layers/ladder-down_module_list-1-conv1.bin",
|
||||
"shelfnet_mapillary/layers/ladder-down_module_list-1-conv12.bin",
|
||||
"shelfnet_mapillary/layers/ladder-down_conv_list-1.bin",
|
||||
|
||||
"shelfnet_mapillary/layers/ladder-bottom-conv1.bin",
|
||||
"shelfnet_mapillary/layers/ladder-bottom-conv12.bin",
|
||||
|
||||
|
||||
|
||||
"shelfnet_mapillary/layers/ladder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/ladder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet_mapillary/layers/ladder-up_dense_list-0-conv.bin",
|
||||
|
||||
|
||||
"shelfnet_mapillary/layers/ladder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet_mapillary/layers/ladder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet_mapillary/layers/ladder-up_dense_list-1-conv.bin"};
|
||||
|
||||
const char *trans[] = {
|
||||
"shelfnet_mapillary/layers/trans1-conv.bin",
|
||||
"shelfnet_mapillary/layers/trans2-conv.bin",
|
||||
"shelfnet_mapillary/layers/trans3-conv.bin"};
|
||||
int main()
|
||||
{
|
||||
|
||||
// downloadWeightsifDoNotExist(input_bin, "shelfnet_mapillary", "");
|
||||
// download the weights from here: https://cloud.hipert.unimore.it/f/652476
|
||||
|
||||
// Mapillary Vistas has originally 66 classes, but we reduced them to 15 to improve the results on the categories of our interest.
|
||||
int classes = 15;
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 3, 1024, 1024, 1);
|
||||
tk::dnn::Network net(dim);
|
||||
|
||||
int bi = 0, di = 0, li = 0, ci = 0;
|
||||
new tk::dnn::Conv2d(&net, 64, 7, 7, 2, 2, 3, 3, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* last = new tk::dnn::Pooling (&net, 3, 3, 2, 2, 1, 1, tk::dnn::POOLING_MAX);
|
||||
|
||||
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
}
|
||||
|
||||
std::vector<tk::dnn::Layer*> features;
|
||||
for(int i=0;i<3;++i){
|
||||
int out_channel = pow(2,7+i);
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 2, 2, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* bn2 = new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 2, 2, 0, 0, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, bn2);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
features.push_back(last);
|
||||
}
|
||||
|
||||
for(int i=0; i<features.size(); ++i){
|
||||
new tk::dnn::Route(&net, &features[i], 1);
|
||||
int out_channel = pow(2,6+i);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, trans[i], true);
|
||||
features[i] = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
}
|
||||
|
||||
//DECODER
|
||||
|
||||
last = features[2];
|
||||
std::vector<tk::dnn::Layer*> up_out;
|
||||
//bottom
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, decoder[di++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, features[1-i]);
|
||||
|
||||
//up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
//LADDER
|
||||
|
||||
std::vector<tk::dnn::Layer*> down_out;
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
for(int i=0; i<2;++i){
|
||||
int out_channel = pow(2,6+i);
|
||||
tk::dnn::Layer* l_last = new tk::dnn::Shortcut(&net, up_out[2-i]);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, l_last);
|
||||
l_last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
down_out.push_back(l_last);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel*2, 3, 3, 2, 2, 1, 1, ladder[li++], false);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.0f); //should be ReLU
|
||||
}
|
||||
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.clear();
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, ladder[li++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, down_out[1-i]);
|
||||
|
||||
// //up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
|
||||
// for(int i=2;i>=0;--i){
|
||||
// new tk::dnn::Route(&net, &up_out[i], 1);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, conv_out[ci++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, classes, 3, 3, 1, 1, 1, 1, conv_out[ci++], false);
|
||||
/*up_out[i] =*/ new tk::dnn::Resize(&net, classes, net.input_dim.h, net.input_dim.w, true, tk::dnn::ResizeMode_t::LINEAR);
|
||||
// }
|
||||
|
||||
new tk::dnn::Softmax(&net);
|
||||
|
||||
const char *output_bin = "shelfnet_mapillary/debug/softmax.bin";
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
|
||||
std::cout<<"Input:"<<std::endl;
|
||||
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// // convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("shelfnet_mapillary"));
|
||||
|
||||
tk::dnn::dataDim_t dim1 = dim; //input dim
|
||||
dnnType *cudnn_out = nullptr;
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TKDNN_TSTART
|
||||
cudnn_out = net.infer(dim1, data);
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
tk::dnn::dataDim_t dim2 = dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
dnnType *rt_out1 = (dnnType *)netRT.buffersRT[1];
|
||||
|
||||
printCenteredTitle(std::string(" CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out1, *out1_h;
|
||||
int odim1 = dim1.tot();
|
||||
readBinaryFile(output_bin, odim1, &out1_h, &out1);
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
std::cout << "CUDNN vs correct" << std::endl;
|
||||
ret_cudnn |= checkResult(odim1, cudnn_out, out1, true, 20) == 0 ? 0 : ERROR_CUDNN;
|
||||
|
||||
std::cout << "TRT vs correct" << std::endl;
|
||||
ret_tensorrt |=checkResult(odim1, rt_out1, out1) == 0 ? 0 : ERROR_TENSORRT;
|
||||
|
||||
std::cout << "CUDNN vs TRT " << std::endl;
|
||||
ret_cudnn_tensorrt |= checkResult(odim1, cudnn_out, rt_out1) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
|
||||
cv::Mat viz = vizLayer2Mat(&net, net.num_layers-1);
|
||||
cv::imwrite("test.png", viz);
|
||||
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include<iostream>
|
||||
#include<algorithm>
|
||||
#include "tkdnn.h"
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
|
||||
@@ -17,6 +18,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(NULL, argv[1]);
|
||||
|
||||
|
||||
|
||||
tk::dnn::dataDim_t idim = netRT.input_dim;
|
||||
tk::dnn::dataDim_t odim = netRT.output_dim;
|
||||
@@ -29,9 +32,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
int ret_tensorrt = 0;
|
||||
std::cout<<"Testing with batchsize: "<<BATCH_SIZE<<"\n";
|
||||
std::vector<double> stats;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
float total_time = 0;
|
||||
for(int i=0; i<1200; i++) {
|
||||
for(int i=0; i<64; i++) {
|
||||
|
||||
// generate input
|
||||
for(int j=0; j<netRT.input_dim.tot(); j++) {
|
||||
@@ -46,18 +50,43 @@ int main(int argc, char *argv[]) {
|
||||
netRT.infer(dim, input_d);
|
||||
TKDNN_TSTOP
|
||||
total_time+= t_ns;
|
||||
if(i> 1)
|
||||
stats.push_back(t_ns);
|
||||
|
||||
// control output
|
||||
std::cout<<"Output Buffers: "<<netRT.getBuffersN()-1<<"\n";
|
||||
// std::cout<<"Output Buffers: "<<netRT.getBuffersN()-1<<"\n";
|
||||
std::cout<<"Img: "<<i<<"\n";
|
||||
for(int o=1; o<netRT.getBuffersN(); o++) {
|
||||
for(int b=1; b<BATCH_SIZE; b++) {
|
||||
dnnType *out_d = (dnnType*) netRT.buffersRT[o];
|
||||
dnnType *out0_d = out_d;
|
||||
dnnType *outI_d = out_d + netRT.buffersDIM[o].tot()*b;
|
||||
ret_tensorrt |= checkResult(netRT.buffersDIM[o].tot(), outI_d, out0_d) == 0 ? 0 : ERROR_TENSORRT;
|
||||
ret_tensorrt |= checkResult(netRT.buffersDIM[o].tot(), outI_d, out0_d,true, 10, false) == 0 ? 0 : ERROR_TENSORRT;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout<<"avg: "<<total_time/1200.<<std::endl;
|
||||
|
||||
double min = *std::min_element(stats.begin(), stats.end())/BATCH_SIZE;
|
||||
double max = *std::max_element(stats.begin(), stats.end())/BATCH_SIZE;
|
||||
double mean =0;
|
||||
for(int i=0; i<stats.size(); i++) mean += stats[i]; mean /= stats.size();
|
||||
mean /=BATCH_SIZE;
|
||||
|
||||
std::cout<<"Min: "<<min<<" ms\n";
|
||||
std::cout<<"Max: "<<max<<" ms\n";
|
||||
std::cout<<"Avg: "<<mean<<" ms\t"<<1000/(mean)<<" FPS\n"<<COL_END;
|
||||
|
||||
|
||||
std::ofstream times;
|
||||
times.open("times_rtinference.csv", std::ios_base::app);
|
||||
|
||||
std::string net_name;
|
||||
removePathAndExtension(argv[1], net_name);
|
||||
|
||||
times << net_name<< "_" << BATCH_SIZE << ";" << mean << ";" << min << ";" << max << ";" << 1000./mean << "\n";
|
||||
|
||||
times.close();
|
||||
|
||||
return ret_tensorrt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user