better network model
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ add_library(tkDNN SHARED src/Layer.cpp src/LayerWgs.cpp
|
||||
src/Route.cpp src/Reorg.cpp src/Region.cpp src/Network.cpp src/utils.cpp)
|
||||
target_link_libraries(tkDNN kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} -lcudnn -lnvinfer)
|
||||
|
||||
add_executable(test_simple tests/test/test_simple.cpp)
|
||||
add_executable(test_simple tests/simple/test_simple.cpp)
|
||||
target_link_libraries(test_simple tkDNN)
|
||||
|
||||
add_executable(test_mnist tests/mnist/test_mnist.cpp)
|
||||
|
||||
+13
-44
@@ -7,40 +7,13 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
/**
|
||||
Data rapresentation beetween layers
|
||||
n = batch size
|
||||
c = channels
|
||||
h = heigth (lines)
|
||||
w = width (rows)
|
||||
l = lenght (3rd dimension)
|
||||
*/
|
||||
struct dataDim_t {
|
||||
|
||||
int n, c, h, w, l;
|
||||
|
||||
dataDim_t() : n(1), c(1), h(1), w(1), l(1) {};
|
||||
|
||||
dataDim_t(int _n, int _c, int _h, int _w, int _l = 1) :
|
||||
n(_n), c(_c), h(_h), w(_w), l(_l) {};
|
||||
|
||||
void print() {
|
||||
std::cout<<"Data dim: "<<n<<" "<<c<<" "<<h<<" "<<w<<" "<<l<<"\n";
|
||||
}
|
||||
|
||||
int tot() {
|
||||
return n*c*h*w*l;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Simple layer Father class
|
||||
*/
|
||||
class Layer {
|
||||
|
||||
public:
|
||||
Layer(Network *net, dataDim_t input_dim);
|
||||
Layer(Network *net);
|
||||
virtual ~Layer();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData) {
|
||||
@@ -64,8 +37,7 @@ protected:
|
||||
class LayerWgs : public Layer {
|
||||
|
||||
public:
|
||||
LayerWgs(Network *net, dataDim_t input_dim,
|
||||
int inputs, int outputs, int kh, int kw, int kt,
|
||||
LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kt,
|
||||
const char* fname_weights, bool batchnorm = false);
|
||||
virtual ~LayerWgs();
|
||||
|
||||
@@ -89,8 +61,7 @@ public:
|
||||
class Dense : public LayerWgs {
|
||||
|
||||
public:
|
||||
Dense(Network *net, dataDim_t in_dim, int out_ch,
|
||||
const char* fname_weights);
|
||||
Dense(Network *net, int out_ch, const char* fname_weights);
|
||||
virtual ~Dense();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -111,7 +82,7 @@ typedef enum {
|
||||
class Activation : public Layer {
|
||||
|
||||
public:
|
||||
Activation(Network *net, dataDim_t input_dim, int act_mode);
|
||||
Activation(Network *net, int act_mode);
|
||||
virtual ~Activation();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -128,9 +99,8 @@ protected:
|
||||
class Conv2d : public LayerWgs {
|
||||
|
||||
public:
|
||||
Conv2d( Network *net, dataDim_t in_dim, int out_ch,
|
||||
int kernelH, int kernelW, int strideH, int strideW,
|
||||
int paddingH, int paddingW,
|
||||
Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
||||
int strideH, int strideW, int paddingH, int paddingW,
|
||||
const char* fname_weights, bool batchnorm = false);
|
||||
virtual ~Conv2d();
|
||||
|
||||
@@ -156,7 +126,7 @@ protected:
|
||||
class Flatten : public Layer {
|
||||
|
||||
public:
|
||||
Flatten(Network *net, dataDim_t input_dim);
|
||||
Flatten(Network *net);
|
||||
virtual ~Flatten();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -170,7 +140,7 @@ public:
|
||||
class MulAdd : public Layer {
|
||||
|
||||
public:
|
||||
MulAdd(Network *net, dataDim_t input_dim, value_type mul, value_type add);
|
||||
MulAdd(Network *net, value_type mul, value_type add);
|
||||
virtual ~MulAdd();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -198,7 +168,7 @@ typedef enum {
|
||||
class Pooling : public Layer {
|
||||
|
||||
public:
|
||||
Pooling(Network *net, dataDim_t input_dim, int winH, int winW,
|
||||
Pooling(Network *net, int winH, int winW,
|
||||
int strideH, int strideW, tkdnnPoolingMode_t pool_mode);
|
||||
virtual ~Pooling();
|
||||
|
||||
@@ -221,7 +191,7 @@ protected:
|
||||
class Softmax : public Layer {
|
||||
|
||||
public:
|
||||
Softmax(Network *net, dataDim_t input_dim);
|
||||
Softmax(Network *net);
|
||||
virtual ~Softmax();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -234,7 +204,7 @@ public:
|
||||
class Route : public Layer {
|
||||
|
||||
public:
|
||||
Route(Network *net, int *layers_id, int layers_n);
|
||||
Route(Network *net, Layer **layers, int layers_n);
|
||||
virtual ~Route();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -252,7 +222,7 @@ public:
|
||||
class Reorg : public Layer {
|
||||
|
||||
public:
|
||||
Reorg(Network *net, dataDim_t input_dim, int stride);
|
||||
Reorg(Network *net, int stride);
|
||||
virtual ~Reorg();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
@@ -268,8 +238,7 @@ protected:
|
||||
class Region : public Layer {
|
||||
|
||||
public:
|
||||
Region(Network *net, dataDim_t input_dim,
|
||||
int classes, int coords, int num, float thresh);
|
||||
Region(Network *net, int classes, int coords, int num, float thresh);
|
||||
virtual ~Region();
|
||||
|
||||
virtual value_type* infer(dataDim_t &dim, value_type* srcData);
|
||||
|
||||
+30
-2
@@ -5,14 +5,39 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
struct dataDim_t;
|
||||
/**
|
||||
Data rapresentation beetween layers
|
||||
n = batch size
|
||||
c = channels
|
||||
h = heigth (lines)
|
||||
w = width (rows)
|
||||
l = lenght (3rd dimension)
|
||||
*/
|
||||
struct dataDim_t {
|
||||
|
||||
int n, c, h, w, l;
|
||||
|
||||
dataDim_t() : n(1), c(1), h(1), w(1), l(1) {};
|
||||
|
||||
dataDim_t(int _n, int _c, int _h, int _w, int _l = 1) :
|
||||
n(_n), c(_c), h(_h), w(_w), l(_l) {};
|
||||
|
||||
void print() {
|
||||
std::cout<<"Data dim: "<<n<<" "<<c<<" "<<h<<" "<<w<<" "<<l<<"\n";
|
||||
}
|
||||
|
||||
int tot() {
|
||||
return n*c*h*w*l;
|
||||
}
|
||||
};
|
||||
|
||||
class Layer;
|
||||
const int MAX_LAYERS = 256;
|
||||
|
||||
class Network {
|
||||
|
||||
public:
|
||||
Network();
|
||||
Network(dataDim_t input_dim);
|
||||
virtual ~Network();
|
||||
|
||||
/**
|
||||
@@ -29,6 +54,9 @@ public:
|
||||
|
||||
Layer* layers[MAX_LAYERS]; //contains layers of the net
|
||||
int num_layers; //current number of layers
|
||||
|
||||
dataDim_t input_dim;
|
||||
dataDim_t getOutputDim();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Activation::Activation(Network *net, dataDim_t input_dim, int act_mode) :
|
||||
Layer(net, input_dim) {
|
||||
Activation::Activation(Network *net, int act_mode) :
|
||||
Layer(net) {
|
||||
|
||||
this->act_mode = act_mode;
|
||||
checkCuda( cudaMalloc(&dstData, input_dim.tot()*sizeof(value_type)) );
|
||||
|
||||
+3
-4
@@ -4,12 +4,11 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Conv2d::Conv2d( Network *net, dataDim_t in_dim, int out_ch,
|
||||
int kernelH, int kernelW, int strideH, int strideW,
|
||||
int paddingH, int paddingW,
|
||||
Conv2d::Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
||||
int strideH, int strideW, int paddingH, int paddingW,
|
||||
const char* fname_weights, bool batchnorm) :
|
||||
|
||||
LayerWgs(net, in_dim, in_dim.c, out_ch, kernelH, kernelW, 1,
|
||||
LayerWgs(net, net->getOutputDim().c, out_ch, kernelH, kernelW, 1,
|
||||
fname_weights, batchnorm) {
|
||||
|
||||
this->kernelH = kernelH;
|
||||
|
||||
+2
-3
@@ -4,9 +4,8 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Dense::Dense(Network *net, dataDim_t in_dim,
|
||||
int out_ch, const char* fname_weights) :
|
||||
LayerWgs(net, in_dim, in_dim.tot(), out_ch, 1, 1, 1, fname_weights) {
|
||||
Dense::Dense(Network *net, int out_ch, const char* fname_weights) :
|
||||
LayerWgs(net, net->getOutputDim().tot(), out_ch, 1, 1, 1, fname_weights) {
|
||||
|
||||
output_dim.n = 1;
|
||||
output_dim.c = out_ch;
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Flatten::Flatten(Network *net, dataDim_t input_dim) :
|
||||
Layer(net, input_dim) {
|
||||
Flatten::Flatten(Network *net) : Layer(net) {
|
||||
|
||||
checkCuda( cudaMalloc(&dstData, input_dim.tot()*sizeof(value_type)) );
|
||||
|
||||
|
||||
+3
-3
@@ -4,11 +4,11 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Layer::Layer(Network *net, dataDim_t in_dim) {
|
||||
Layer::Layer(Network *net) {
|
||||
|
||||
this->net = net;
|
||||
this->input_dim = in_dim;
|
||||
this->output_dim = in_dim;
|
||||
this->input_dim = net->getOutputDim();
|
||||
this->output_dim = input_dim;
|
||||
|
||||
checkCUDNN( cudnnCreateTensorDescriptor(&srcTensorDesc) );
|
||||
checkCUDNN( cudnnCreateTensorDescriptor(&dstTensorDesc) );
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
LayerWgs::LayerWgs(Network *net, dataDim_t in_dim,
|
||||
int inputs, int outputs, int kh, int kw, int kl,
|
||||
const char* fname_weights, bool batchnorm) : Layer(net, in_dim) {
|
||||
LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
|
||||
int kh, int kw, int kl,
|
||||
const char* fname_weights, bool batchnorm) : Layer(net) {
|
||||
|
||||
this->inputs = inputs;
|
||||
this->outputs = outputs;
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
MulAdd::MulAdd(Network *net, dataDim_t input_dim, value_type mul, value_type add) :
|
||||
Layer(net, input_dim) {
|
||||
MulAdd::MulAdd(Network *net, value_type mul, value_type add) : Layer(net) {
|
||||
|
||||
this->mul = mul;
|
||||
this->add = add;
|
||||
|
||||
+10
-1
@@ -7,7 +7,8 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Network::Network() {
|
||||
Network::Network(dataDim_t input_dim) {
|
||||
this->input_dim = input_dim;
|
||||
|
||||
float tk_ver = float(tkDNN::getVersion())/1000;
|
||||
float cu_ver = float(cudnnGetVersion())/1000;
|
||||
@@ -47,4 +48,12 @@ bool Network::addLayer(Layer *l) {
|
||||
return true;
|
||||
}
|
||||
|
||||
dataDim_t Network::getOutputDim() {
|
||||
|
||||
if(num_layers == 0)
|
||||
return input_dim;
|
||||
else
|
||||
return layers[num_layers-1]->output_dim;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -5,9 +5,9 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Pooling::Pooling( Network *net, dataDim_t input_dim,
|
||||
int winH, int winW, int strideH, int strideW, tkdnnPoolingMode_t pool_mode) :
|
||||
Layer(net, input_dim) {
|
||||
Pooling::Pooling( Network *net, int winH, int winW,
|
||||
int strideH, int strideW, tkdnnPoolingMode_t pool_mode) :
|
||||
Layer(net) {
|
||||
|
||||
|
||||
if(winH != strideH || winW != strideW)
|
||||
|
||||
+2
-3
@@ -5,9 +5,8 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Region::Region(Network *net, dataDim_t input_dim,
|
||||
int classes, int coords, int num, float thresh) :
|
||||
Layer(net, input_dim) {
|
||||
Region::Region(Network *net, int classes, int coords, int num, float thresh) :
|
||||
Layer(net) {
|
||||
|
||||
this->classes = classes;
|
||||
this->coords = coords;
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Reorg::Reorg(Network *net, dataDim_t input_dim, int stride) :
|
||||
Layer(net, input_dim) {
|
||||
Reorg::Reorg(Network *net, int stride) : Layer(net) {
|
||||
|
||||
this->stride = stride;
|
||||
|
||||
|
||||
+2
-8
@@ -5,17 +5,11 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Route::Route(Network *net, int *layers_id, int layers_n) :
|
||||
Layer(net, dataDim_t()) {
|
||||
Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) {
|
||||
|
||||
this->layers = layers;
|
||||
this->layers_n = layers_n;
|
||||
|
||||
//get layers
|
||||
layers = new Layer*[layers_n];
|
||||
for(int i=0; i<layers_n; i++)
|
||||
layers[i] = net->layers[layers_id[i]];
|
||||
|
||||
|
||||
//get dims
|
||||
output_dim.l = 1;
|
||||
output_dim.c = 0;
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@
|
||||
|
||||
namespace tkDNN {
|
||||
|
||||
Softmax::Softmax(Network *net, dataDim_t input_dim) :
|
||||
Layer(net, input_dim) {
|
||||
Softmax::Softmax(Network *net) : Layer(net) {
|
||||
|
||||
checkCuda( cudaMalloc(&dstData, input_dim.tot()*sizeof(value_type)) );
|
||||
|
||||
|
||||
Executable → Regular
@@ -11,17 +11,16 @@ const char *output_bin = "../tests/mnist/output.bin";
|
||||
int main() {
|
||||
|
||||
// Network layout
|
||||
tkDNN::Network net;
|
||||
tkDNN::dataDim_t dim(1, 1, 28, 28, 1);
|
||||
tkDNN::Layer *l;
|
||||
l = new tkDNN::Conv2d (&net, dim, 20, 5, 5, 1, 1, 0, 0, c0_bin);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 50, 5, 5, 1, 1, 0, 0, c1_bin);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 500, d2_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 10, d3_bin);
|
||||
l = new tkDNN::Softmax (&net, l->output_dim);
|
||||
tkDNN::Network net(dim);
|
||||
tkDNN::Conv2d l0(&net, 20, 5, 5, 1, 1, 0, 0, c0_bin);
|
||||
tkDNN::Pooling l1(&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Conv2d l2(&net, 50, 5, 5, 1, 1, 0, 0, c1_bin);
|
||||
tkDNN::Pooling l3(&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Dense l4(&net, 500, d2_bin);
|
||||
tkDNN::Activation l5(&net, CUDNN_ACTIVATION_RELU);
|
||||
tkDNN::Dense l6(&net, 10, d3_bin);
|
||||
tkDNN::Softmax l7(&net);
|
||||
|
||||
// Load input
|
||||
value_type *data;
|
||||
|
||||
@@ -27,17 +27,16 @@ int main() {
|
||||
|
||||
std::cout<<"\n==== CUDNN ====\n";
|
||||
// Network layout
|
||||
tkDNN::Network net;
|
||||
tkDNN::dataDim_t dim(1, 1, 28, 28, 1);
|
||||
tkDNN::Layer *l;
|
||||
l = new tkDNN::Conv2d (&net, dim, 20, 5, 5, 1, 1, 0, 0, c0_bin);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 50, 5, 5, 1, 1, 0, 0, c1_bin);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 500, d2_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 10, d3_bin);
|
||||
l = new tkDNN::Softmax (&net, l->output_dim);
|
||||
tkDNN::Network net(dim);
|
||||
tkDNN::Conv2d l0(&net, 20, 5, 5, 1, 1, 0, 0, c0_bin);
|
||||
tkDNN::Pooling l1(&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Conv2d l2(&net, 50, 5, 5, 1, 1, 0, 0, c1_bin);
|
||||
tkDNN::Pooling l3(&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Dense l4(&net, 500, d2_bin);
|
||||
tkDNN::Activation l5(&net, CUDNN_ACTIVATION_RELU);
|
||||
tkDNN::Dense l6(&net, 10, d3_bin);
|
||||
tkDNN::Softmax l7(&net);
|
||||
|
||||
// Load input
|
||||
value_type *data;
|
||||
@@ -72,7 +71,7 @@ int main() {
|
||||
auto input = network->addInput("data", dt, DimsCHW{ 1, 28, 28});
|
||||
assert(input != nullptr);
|
||||
|
||||
tkDNN::Conv2d *c0 = (tkDNN::Conv2d*) (net.layers[0]);
|
||||
tkDNN::Conv2d *c0 = &l0;
|
||||
Weights w { dt, c0->data_h, c0->inputs*c0->outputs*c0->kernelH*c0->kernelW};
|
||||
Weights b { dt, c0->bias_h, c0->outputs};
|
||||
// Add a convolution layer with 20 outputs and a 5x5 filter.
|
||||
@@ -85,7 +84,7 @@ int main() {
|
||||
assert(pool1 != nullptr);
|
||||
pool1->setStride(DimsHW{2, 2});
|
||||
|
||||
tkDNN::Conv2d *c1 = (tkDNN::Conv2d*) (net.layers[2]);
|
||||
tkDNN::Conv2d *c1 = &l2;
|
||||
Weights w1 { dt, c1->data_h, c1->inputs*c1->outputs*c1->kernelH*c1->kernelW};
|
||||
Weights b1 { dt, c1->bias_h, c1->outputs};
|
||||
// Add a second convolution layer with 50 outputs and a 5x5 filter.
|
||||
@@ -98,7 +97,7 @@ int main() {
|
||||
assert(pool2 != nullptr);
|
||||
pool2->setStride(DimsHW{2, 2});
|
||||
|
||||
tkDNN::Dense *d2 = (tkDNN::Dense*) (net.layers[4]);
|
||||
tkDNN::Dense *d2 = &l4;
|
||||
Weights w2 { dt, d2->data_h, d2->inputs*d2->outputs};
|
||||
Weights b2 { dt, d2->bias_h, d2->outputs};
|
||||
// Add a fully connected layer with 500 outputs.
|
||||
@@ -109,7 +108,7 @@ int main() {
|
||||
auto relu1 = network->addActivation(*ip1->getOutput(0), ActivationType::kRELU);
|
||||
assert(relu1 != nullptr);
|
||||
|
||||
tkDNN::Conv2d *d3 = (tkDNN::Conv2d*) (net.layers[6]);
|
||||
tkDNN::Dense *d3 = &l6;
|
||||
Weights w3 { dt, d3->data_h, d3->inputs*d3->outputs};
|
||||
Weights b3 { dt, d3->bias_h, d3->outputs};
|
||||
// Add a second fully connected layer with 20 outputs.
|
||||
|
||||
@@ -10,16 +10,15 @@ const char *output_bin = "../tests/test/output.bin";
|
||||
int main() {
|
||||
|
||||
// Network layout
|
||||
tkDNN::Network net;
|
||||
tkDNN::dataDim_t dim(1, 1, 10, 10, 1);
|
||||
tkDNN::Layer *l;
|
||||
l = new tkDNN::Conv2d (&net, dim, 2, 4, 4, 2, 2, 0, 0, c0_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 4, 2, 2, 1, 1, 0, 0, c1_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU);
|
||||
l = new tkDNN::Flatten (&net, l->output_dim);
|
||||
l = new tkDNN::Dense (&net, l->output_dim, 4, d2_bin);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, CUDNN_ACTIVATION_RELU);
|
||||
tkDNN::Network net(dim);
|
||||
tkDNN::Conv2d l0(&net, 2, 4, 4, 2, 2, 0, 0, c0_bin);
|
||||
tkDNN::Activation l1(&net, CUDNN_ACTIVATION_RELU);
|
||||
tkDNN::Conv2d l2(&net, 4, 2, 2, 1, 1, 0, 0, c1_bin);
|
||||
tkDNN::Activation l3(&net, CUDNN_ACTIVATION_RELU);
|
||||
tkDNN::Flatten l4(&net);
|
||||
tkDNN::Dense l5(&net, 4, d2_bin);
|
||||
tkDNN::Activation l6(&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
// Load input
|
||||
value_type *data;
|
||||
@@ -30,11 +29,8 @@ int main() {
|
||||
dim.print(); //print initial dimension
|
||||
|
||||
TIMER_START
|
||||
|
||||
// Inference
|
||||
data = net.infer(dim, data); dim.print();
|
||||
|
||||
|
||||
TIMER_STOP
|
||||
|
||||
// Print result
|
||||
+58
-58
@@ -30,74 +30,74 @@ const char *output_bin = "../tests/yolo/layers/output.bin";
|
||||
int main() {
|
||||
|
||||
// Network layout
|
||||
tkDNN::Network net;
|
||||
tkDNN::dataDim_t dim(1, 3, 608, 608, 1);
|
||||
tkDNN::Layer *l;
|
||||
l = new tkDNN::Conv2d (&net, dim, 32, 3, 3, 1, 1, 1, 1, c0_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Network net(dim);
|
||||
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 64, 3, 3, 1, 1, 1, 1, c2_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true);
|
||||
tkDNN::Activation a0 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Pooling p1 (&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 128, 3, 3, 1, 1, 1, 1, c4_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 64, 1, 1, 1, 1, 0, 0, c5_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 128, 3, 3, 1, 1, 1, 1, c6_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Conv2d c2 (&net, 64, 3, 3, 1, 1, 1, 1, c2_bin, true);
|
||||
tkDNN::Activation a2 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Pooling p3 (&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 256, 3, 3, 1, 1, 1, 1, c8_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 128, 1, 1, 1, 1, 0, 0, c9_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 256, 3, 3, 1, 1, 1, 1, c10_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Conv2d c4 (&net, 128, 3, 3, 1, 1, 1, 1, c4_bin, true);
|
||||
tkDNN::Activation a4 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c5 (&net, 64, 1, 1, 1, 1, 0, 0, c5_bin, true);
|
||||
tkDNN::Activation a5 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true);
|
||||
tkDNN::Activation a6 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Pooling p7 (&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 512, 3, 3, 1, 1, 1, 1, c12_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 256, 1, 1, 1, 1, 0, 0, c13_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 512, 3, 3, 1, 1, 1, 1, c14_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 256, 1, 1, 1, 1, 0, 0, c15_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 512, 3, 3, 1, 1, 1, 1, c16_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY); //29
|
||||
l = new tkDNN::Pooling (&net, l->output_dim, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
tkDNN::Conv2d c8 (&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true);
|
||||
tkDNN::Activation a8 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c9 (&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true);
|
||||
tkDNN::Activation a9 (&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c10(&net, 256, 3, 3, 1, 1, 1, 1, c10_bin, true);
|
||||
tkDNN::Activation a10(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Pooling p11(&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 1024, 3, 3, 1, 1, 1, 1, c18_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 512, 1, 1, 1, 1, 0, 0, c19_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 1024, 3, 3, 1, 1, 1, 1, c20_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 512, 1, 1, 1, 1, 0, 0, c21_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 1024, 3, 3, 1, 1, 1, 1, c22_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 1024, 3, 3, 1, 1, 1, 1, c23_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 1024, 3, 3, 1, 1, 1, 1, c24_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY); //44
|
||||
tkDNN::Conv2d c12(&net, 512, 3, 3, 1, 1, 1, 1, c12_bin, true);
|
||||
tkDNN::Activation a12(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true);
|
||||
tkDNN::Activation a13(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true);
|
||||
tkDNN::Activation a14(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c15(&net, 256, 1, 1, 1, 1, 0, 0, c15_bin, true);
|
||||
tkDNN::Activation a15(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c16(&net, 512, 3, 3, 1, 1, 1, 1, c16_bin, true);
|
||||
tkDNN::Activation a16(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Pooling p17(&net, 2, 2, 2, 2, tkDNN::POOLING_MAX);
|
||||
|
||||
int rlayers[1] = {29};
|
||||
l = new tkDNN::Route (&net, rlayers, 1);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 64, 1, 1, 1, 1, 0, 0, c26_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Reorg (&net, l->output_dim, 2); //48
|
||||
tkDNN::Conv2d c18(&net, 1024, 3, 3, 1, 1, 1, 1, c18_bin, true);
|
||||
tkDNN::Activation a18(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c19(&net, 512, 1, 1, 1, 1, 0, 0, c19_bin, true);
|
||||
tkDNN::Activation a19(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c20(&net, 1024, 3, 3, 1, 1, 1, 1, c20_bin, true);
|
||||
tkDNN::Activation a20(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c21(&net, 512, 1, 1, 1, 1, 0, 0, c21_bin, true);
|
||||
tkDNN::Activation a21(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c22(&net, 1024, 3, 3, 1, 1, 1, 1, c22_bin, true);
|
||||
tkDNN::Activation a22(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c23(&net, 1024, 3, 3, 1, 1, 1, 1, c23_bin, true);
|
||||
tkDNN::Activation a23(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c24(&net, 1024, 3, 3, 1, 1, 1, 1, c24_bin, true);
|
||||
tkDNN::Activation a24(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
|
||||
int rlayers2[2] = {48,44};
|
||||
l = new tkDNN::Route (&net, rlayers2, 2);
|
||||
tkDNN::Layer *m25_layers[1] = { &a16 };
|
||||
tkDNN::Route m25(&net, m25_layers, 1);
|
||||
tkDNN::Conv2d c26(&net, 64, 1, 1, 1, 1, 0, 0, c26_bin, true);
|
||||
tkDNN::Activation a26(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Reorg r27(&net, 2);
|
||||
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true);
|
||||
l = new tkDNN::Activation (&net, l->output_dim, tkDNN::ACTIVATION_LEAKY);
|
||||
l = new tkDNN::Conv2d (&net, l->output_dim, 425, 1, 1, 1, 1, 0, 0, c30_bin, false);
|
||||
tkDNN::Layer *m28_layers[2] = { &r27, &a24 };
|
||||
tkDNN::Route m28(&net, m28_layers, 2);
|
||||
|
||||
l = new tkDNN::Region (&net, l->output_dim, 80, 4, 5, 0.6f);
|
||||
tkDNN::Conv2d c29(&net, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true);
|
||||
tkDNN::Activation a29(&net, tkDNN::ACTIVATION_LEAKY);
|
||||
tkDNN::Conv2d c30(&net, 425, 1, 1, 1, 1, 0, 0, c30_bin, false);
|
||||
|
||||
tkDNN::Region g31(&net, 80, 4, 5, 0.6f);
|
||||
|
||||
// Load input
|
||||
value_type *data;
|
||||
|
||||
Reference in New Issue
Block a user