network print

This commit is contained in:
Francesco Gatti
2017-08-08 14:59:25 +02:00
parent 7d570c0df4
commit 0a9957ba18
6 changed files with 69 additions and 2 deletions
+17
View File
@@ -38,6 +38,23 @@ public:
dataDim_t input_dim, output_dim;
value_type *dstData; //where results will be putted
std::string getLayerName() {
layerType_t type = getLayerType();
switch(type) {
case LAYER_DENSE: return "Dense";
case LAYER_CONV2D: return "Conv2d";
case LAYER_ACTIVATION: return "Activation";
case LAYER_FLATTEN: return "Flatten";
case LAYER_MULADD: return "MulAdd";
case LAYER_POOLING: return "Pooling";
case LAYER_SOFTMAX: return "Softmax";
case LAYER_ROUTE: return "Route";
case LAYER_REORG: return "Reorg";
case LAYER_REGION: return "Region";
default: return "unknown";
}
}
protected:
Network *net;
cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
+1
View File
@@ -46,6 +46,7 @@ public:
value_type* infer(dataDim_t &dim, value_type* data);
bool addLayer(Layer *l);
void print();
cudnnDataType_t dataType;
cudnnTensorFormat_t tensorFormat;
+1
View File
@@ -87,6 +87,7 @@
} \
}
void printCenteredTitle(const char *title, char fill, int dim);
void readBinaryFile(const char* fname, int size, value_type** data_h, value_type** data_d, int seek = 0);
int checkResult(int size, value_type *data_d, value_type *correct_d, bool device = true);
void printDeviceVector(int size, value_type* vec_d, bool device = true);
+37 -1
View File
@@ -1,4 +1,5 @@
#include <iostream>
#include <string>
#include "tkdnn.h"
#include "Network.h"
@@ -34,7 +35,6 @@ value_type* Network::infer(dataDim_t &dim, value_type* data) {
//do infer for every layer
for(int i=0; i<num_layers; i++) {
data = layers[i]->infer(dim, data);
//dim.print();
}
checkCuda(cudaDeviceSynchronize());
return data;
@@ -56,4 +56,40 @@ dataDim_t Network::getOutputDim() {
return layers[num_layers-1]->output_dim;
}
void Network::print() {
std::cout<<"\n";
printCenteredTitle(" NETWORK MODEL ", '=', 60);
std::cout.width(3); std::cout<<std::left<<"N.";
std::cout<<" ";
std::cout.width(17); std::cout<<std::left<<"Layer type";
std::cout.width(22); std::cout<<std::left<<"input (H*W,CH)";
std::cout.width(16); std::cout<<std::left<<"output (H*W,CH)";
std::cout<<"\n";
for(int i=0; i<num_layers; i++) {
dataDim_t in = layers[i]->input_dim;
dataDim_t out = layers[i]->output_dim;
std::cout.width(3); std::cout<<std::right<<i;
std::cout<<" ";
std::cout.width(16); std::cout<<std::left<<layers[i]->getLayerName();
std::cout.width(4); std::cout<<std::right<<in.h;
std::cout<<" x ";
std::cout.width(4); std::cout<<std::right<<in.w;
std::cout<<", ";
std::cout.width(4); std::cout<<std::right<<in.c;
std::cout<<" -> ";
std::cout.width(4); std::cout<<std::right<<out.h;
std::cout<<" x ";
std::cout.width(4); std::cout<<std::right<<out.w;
std::cout<<", ";
std::cout.width(4); std::cout<<std::right<<out.c;
std::cout<<"\n";
}
printCenteredTitle("", '=', 60);
std::cout<<"\n";
}
}
+12
View File
@@ -1,4 +1,16 @@
#include "utils.h"
#include <string.h>
void printCenteredTitle(const char *title, char fill, int dim) {
int len = strlen(title);
int first = dim/2 + len/2;
std::cout.width(first); std::cout.fill(fill); std::cout<<std::right<<title;
std::cout.width(dim - first); std::cout<<"\n";
std::cout.fill(' ');
}
void readBinaryFile(const char* fname, int size, value_type** data_h, value_type** data_d, int seek)
{
+1 -1
View File
@@ -42,7 +42,7 @@ int main() {
tkDNN::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true);
tkDNN::Activation a10(&net, tkDNN::ACTIVATION_LEAKY);
tkDNN::Pooling p11(&net, 2, 2, 1, 1, tkDNN::POOLING_MAX);
//tkDNN::Pooling p11(&net, 2, 2, 1, 1, tkDNN::POOLING_MAX);
tkDNN::Conv2d c12(&net, 1024, 3, 3, 1, 1, 1, 1, c12_bin, true);
tkDNN::Activation a12(&net, tkDNN::ACTIVATION_LEAKY);