network print
This commit is contained in:
@@ -38,6 +38,23 @@ public:
|
|||||||
dataDim_t input_dim, output_dim;
|
dataDim_t input_dim, output_dim;
|
||||||
value_type *dstData; //where results will be putted
|
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:
|
protected:
|
||||||
Network *net;
|
Network *net;
|
||||||
cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
|
cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ public:
|
|||||||
value_type* infer(dataDim_t &dim, value_type* data);
|
value_type* infer(dataDim_t &dim, value_type* data);
|
||||||
|
|
||||||
bool addLayer(Layer *l);
|
bool addLayer(Layer *l);
|
||||||
|
void print();
|
||||||
|
|
||||||
cudnnDataType_t dataType;
|
cudnnDataType_t dataType;
|
||||||
cudnnTensorFormat_t tensorFormat;
|
cudnnTensorFormat_t tensorFormat;
|
||||||
|
|||||||
@@ -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);
|
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);
|
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);
|
void printDeviceVector(int size, value_type* vec_d, bool device = true);
|
||||||
|
|||||||
+37
-1
@@ -1,4 +1,5 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "tkdnn.h"
|
#include "tkdnn.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
@@ -34,7 +35,6 @@ value_type* Network::infer(dataDim_t &dim, value_type* data) {
|
|||||||
//do infer for every layer
|
//do infer for every layer
|
||||||
for(int i=0; i<num_layers; i++) {
|
for(int i=0; i<num_layers; i++) {
|
||||||
data = layers[i]->infer(dim, data);
|
data = layers[i]->infer(dim, data);
|
||||||
//dim.print();
|
|
||||||
}
|
}
|
||||||
checkCuda(cudaDeviceSynchronize());
|
checkCuda(cudaDeviceSynchronize());
|
||||||
return data;
|
return data;
|
||||||
@@ -56,4 +56,40 @@ dataDim_t Network::getOutputDim() {
|
|||||||
return layers[num_layers-1]->output_dim;
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
#include "utils.h"
|
#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)
|
void readBinaryFile(const char* fname, int size, value_type** data_h, value_type** data_d, int seek)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ int main() {
|
|||||||
|
|
||||||
tkDNN::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true);
|
tkDNN::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true);
|
||||||
tkDNN::Activation a10(&net, tkDNN::ACTIVATION_LEAKY);
|
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::Conv2d c12(&net, 1024, 3, 3, 1, 1, 1, 1, c12_bin, true);
|
||||||
tkDNN::Activation a12(&net, tkDNN::ACTIVATION_LEAKY);
|
tkDNN::Activation a12(&net, tkDNN::ACTIVATION_LEAKY);
|
||||||
|
|||||||
Reference in New Issue
Block a user