diff --git a/src/cnn/include/print.h b/src/cnn/include/print.h new file mode 100644 index 0000000..8969760 --- /dev/null +++ b/src/cnn/include/print.h @@ -0,0 +1,32 @@ +#ifndef DEF_PRINT_H +#define DEF_PRINT_H + +#include "include/struct.h" + +/* +* Affiche le kernel d'une couche de convolution +*/ +void print_kernel_cnn(Kernel_cnn* k, int depth_input, int dim_input, int depth_output, int dim_output); + +/* +* Affiche une couche de pooling +*/ +void print_pooling(int size); + +/* +* Affiche le kernel d'une couche de fully connected +*/ +void print_kernel_nn(Kernel_nn* k, int size_input, int size_output); + +/* +* Affiche une couche d'input +*/ +void print_input(float*** input, int depth, int dim); + +/* +* Affiche un cnn. Plus précisément: +* input, kernel_cnn, kernel_nn, pooling +*/ +void print_cnn(Network* network); + +#endif \ No newline at end of file diff --git a/src/cnn/print.c b/src/cnn/print.c new file mode 100644 index 0000000..8048e6b --- /dev/null +++ b/src/cnn/print.c @@ -0,0 +1,123 @@ +#include +#include "include/print.h" + +#define print_bar printf("---------------------------\n") +#define print_space printf("\n") +#define print_dspace printf("\n\n") +#define print_tspace printf("\n\n\n") +#define green printf("\033[0;31m") +#define red printf("\033[0;32m") +#define blue printf("\033[0;34m") +#define purple printf("\033[0;35m") +#define reset_color printf("\033[0m") + +void print_kernel_cnn(Kernel_cnn* k, int depth_input, int dim_input, int depth_output, int dim_output) { + int k_size = dim_input - dim_output + 1; + // print bias + green; + for (int i=0; ibias[i][j][k]); + } + print_space; + } + print_dspace; + } + print_dspace; + reset_color; + + //print weights + red; + for (int i=0; i<; i++) { + printf("------Line %d-----\n", i); + for (int j=0; j<; j++) { + for (int k=0; k<; k++) { + for (int l=0; l<; l++) { + printf("%.2f", k->w[i][j][k][l]); + } + print_space; + } + print_dspace; + } + print_dspace; + } + reset_color; + print_dspace; + +} + +void print_pooling(int size) { + print_bar; + purple; + printf("-------Pooling %dx%d-------\n", size ,size); + reset_color; + print_bar; + print_dspace; +} + +void print_kernel_nn(Kernel_nn* k, int size_input, int size_output) { + // print bias + green; + for (int i=0; ibias[i]); + } + print_dspace; + reset_color; + + //print weights + red; + for (int i=0; iweights[j][i]); + } + print_space; + } + reset_color; + print_dspace; +} + +void print_input(float*** input, int depth, int dim) { + print_bar; + print_bar; + blue; + for (int i=0; isize; + int input_depth, input_width, output_depth, output_width; + Kernel* k_i; + for (int i=0; i<(n-1); i++) { + input = network->input[i]; + input_depth = network->depth[i]; + input_width = network->width[i]; + output = network->input[i+1]; + output_depth = network->depth[i+1]; + output_width = network->width[i+1]; + k_i = network->kernel[i]; + + print_input(input, input_depth, input_width); + + if (k_i->cnn) { // Convolution + print_kernel_cnn(k_i->cnn, input_depth, input_width, output_depth, output_width); + } + else if (k_i->nn) { // Full connection + print_kernel_nn(k_i->nn, input_width, output_width); + } + else { // Pooling + print_pooling(input_width - output_width +1); + } + } + print_input(input[n-1], network->depth[n-1], network->width[n-1]); +} \ No newline at end of file