From cea4132e2d6162c91ec5ba88f91a599de3d5a26d Mon Sep 17 00:00:00 2001 From: augustin64 Date: Tue, 17 Jan 2023 15:34:29 +0100 Subject: [PATCH] Remove white spaces --- src/cnn/cnn.c | 8 ++++---- src/cnn/convolution.c | 6 +++--- src/cnn/convolution.cu | 6 +++--- src/cnn/creation.c | 34 ++++++++++++++++---------------- src/cnn/function.c | 4 ---- src/cnn/include/neuron_io.h | 4 ++-- src/cnn/initialisation.c | 16 +++++++-------- src/cnn/jpeg.c | 6 +++--- src/cnn/matrix_multiplication.cu | 4 ++-- src/cnn/neuron_io.c | 4 ++-- src/cnn/test_network.c | 4 ++-- src/cnn/train.c | 16 +++++++-------- src/cnn/update.c | 2 +- src/cnn/utils.c | 4 ++-- 14 files changed, 57 insertions(+), 61 deletions(-) diff --git a/src/cnn/cnn.c b/src/cnn/cnn.c index fbf7949..744a1df 100644 --- a/src/cnn/cnn.c +++ b/src/cnn/cnn.c @@ -19,7 +19,7 @@ int indice_max(float* tab, int n) { int indice = -1; float maxi = FLT_MIN; - + for (int i=0; i < n; i++) { if (tab[i] > maxi) { maxi = tab[i]; @@ -134,7 +134,7 @@ void backward_propagation(Network* network, float wanted_number) { float*** input_z; float*** output; Kernel* k_i; - + softmax_backward(network->input[n-1][0][0], network->input_z[n-1][0][0], wanted_output, network->width[n-1]); // Backward sur la dernière colonne for (int i=n-2; i >= 0; i--) { @@ -149,7 +149,7 @@ void backward_propagation(Network* network, float wanted_number) { output_width = network->width[i+1]; activation = i==0?SIGMOID:network->kernel[i-1]->activation; - + if (k_i->cnn) { // Convolution ptr d_f = get_function_activation(activation); backward_convolution(k_i->cnn, input, input_z, output, input_depth, input_width, output_depth, output_width, d_f, i==0); @@ -214,7 +214,7 @@ float compute_cross_entropy_loss(float* output, float* wanted_output, int len) { } return loss; } - + float* generate_wanted_output(float wanted_number) { float* wanted_output = (float*)malloc(sizeof(float)*10); for (int i=0; i < 10; i++) { diff --git a/src/cnn/convolution.c b/src/cnn/convolution.c index baf7689..7403137 100644 --- a/src/cnn/convolution.c +++ b/src/cnn/convolution.c @@ -44,7 +44,7 @@ void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, i // input[kernel->rows][kernel_k_size + output_dim-1][kernel_k_size + output_dim-1] // output[kernel->columns][output_dim][output_dim] float f; - + for (int i=0; i < kernel->columns; i++) { for (int j=0; j < output_dim; j++) { for (int k=0; k < output_dim; k++) { @@ -83,7 +83,7 @@ __global__ void make_convolution_kernel(int k_size, int columns, int rows, float bias_offset = (float*)((char*)bias + (idx*output_dim+idy)*pitch_bias); float f = bias_offset[idz]; - + for (int a=0; a < rows; a++) { for (int b=0; b < k_size; b++) { for (int c=0; c < k_size; c++) { @@ -110,7 +110,7 @@ void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output float**** kernel_weight; int input_dim = output_dim+kernel->k_size - 1; - + // Copy ***input gpuErrchk( cudaMallocPitch((void**)&input_dev, &pitch_input, input_dim*sizeof(float), kernel->rows*input_dim)); for (int i=0; i < kernel->rows; i++) { diff --git a/src/cnn/convolution.cu b/src/cnn/convolution.cu index 293c6a2..072cdf1 100644 --- a/src/cnn/convolution.cu +++ b/src/cnn/convolution.cu @@ -44,7 +44,7 @@ void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, i // input[kernel->rows][kernel_k_size + output_dim-1][kernel_k_size + output_dim-1] // output[kernel->columns][output_dim][output_dim] float f; - + for (int i=0; i < kernel->columns; i++) { for (int j=0; j < output_dim; j++) { for (int k=0; k < output_dim; k++) { @@ -83,7 +83,7 @@ __global__ void make_convolution_kernel(int k_size, int columns, int rows, float bias_offset = (float*)((char*)bias + (idx*output_dim+idy)*pitch_bias); float f = bias_offset[idz]; - + for (int a=0; a < rows; a++) { for (int b=0; b < k_size; b++) { for (int c=0; c < k_size; c++) { @@ -110,7 +110,7 @@ void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output float**** kernel_weight; int input_dim = output_dim+kernel->k_size - 1; - + // Copy ***input gpuErrchk( cudaMallocPitch((void**)&input_dev, &pitch_input, input_dim*sizeof(float), kernel->rows*input_dim)); for (int i=0; i < kernel->rows; i++) { diff --git a/src/cnn/creation.c b/src/cnn/creation.c index 7c6d559..28af73f 100644 --- a/src/cnn/creation.c +++ b/src/cnn/creation.c @@ -10,32 +10,32 @@ Network* create_network(int max_size, float learning_rate, int dropout, int init if (dropout < 0 || dropout > 100) { printf("Erreur, la probabilité de dropout n'est pas respecté, elle doit être comprise entre 0 et 100\n"); } - Network* network = (Network*)malloc(sizeof(Network)); + Network* network = (Network*)malloc(sizeof(Network)); network->learning_rate = learning_rate; - network->max_size = max_size; - network->dropout = dropout; - network->initialisation = initialisation; - network->size = 1; - network->input = (float****)malloc(sizeof(float***)*max_size); - network->input_z = (float****)malloc(sizeof(float***)*max_size); - network->kernel = (Kernel**)malloc(sizeof(Kernel*)*(max_size-1)); - network->width = (int*)malloc(sizeof(int*)*max_size); - network->depth = (int*)malloc(sizeof(int*)*max_size); + network->max_size = max_size; + network->dropout = dropout; + network->initialisation = initialisation; + network->size = 1; + network->input = (float****)malloc(sizeof(float***)*max_size); + network->input_z = (float****)malloc(sizeof(float***)*max_size); + network->kernel = (Kernel**)malloc(sizeof(Kernel*)*(max_size-1)); + network->width = (int*)malloc(sizeof(int*)*max_size); + network->depth = (int*)malloc(sizeof(int*)*max_size); for (int i=0; i < max_size-1; i++) { network->kernel[i] = (Kernel*)malloc(sizeof(Kernel)); } - network->width[0] = input_dim; - network->depth[0] = input_depth; - network->kernel[0]->nn = NULL; - network->kernel[0]->cnn = NULL; + network->width[0] = input_dim; + network->depth[0] = input_depth; + network->kernel[0]->nn = NULL; + network->kernel[0]->cnn = NULL; create_a_cube_input_layer(network, 0, input_depth, input_dim); - create_a_cube_input_z_layer(network, 0, input_depth, input_dim); + create_a_cube_input_z_layer(network, 0, input_depth, input_dim); return network; } Network* create_network_lenet5(float learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth) { Network* network = create_network(8, learning_rate, dropout, initialisation, input_dim, input_depth); - network->kernel[0]->activation = activation; + network->kernel[0]->activation = activation; network->kernel[0]->linearisation = 0; add_convolution(network, 6, 28, activation); add_2d_average_pooling(network, 14); @@ -209,7 +209,7 @@ void add_dense_linearisation(Network* network, int output_units, int activation) network->kernel[k_pos]->linearisation = 1; nn->input_units = input_units; nn->output_units = output_units; - + nn->bias = (float*)malloc(sizeof(float)*output_units); nn->d_bias = (float*)calloc(output_units, sizeof(float)); nn->weights = (float**)malloc(sizeof(float*)*input_units); diff --git a/src/cnn/function.c b/src/cnn/function.c index 40d8f22..d7d28c9 100644 --- a/src/cnn/function.c +++ b/src/cnn/function.c @@ -147,7 +147,3 @@ ptr get_function_activation(int activation) { printf("Erreur, fonction d'activation inconnue (choose_apply_function_vector): %d\n", activation); return NULL; } -// to use: -// float a = 5; int activation; -// pm u = get_function_activation; -// printf("%f", (*u(activation))(a)); diff --git a/src/cnn/include/neuron_io.h b/src/cnn/include/neuron_io.h index 5445b76..64206f5 100644 --- a/src/cnn/include/neuron_io.h +++ b/src/cnn/include/neuron_io.h @@ -10,7 +10,7 @@ -// Écriture d'un réseau neuronal +// Écriture d'un réseau neuronal /* * Écrit un réseau neuronal dans un fichier donné @@ -23,7 +23,7 @@ void write_network(char* filename, Network* network); void write_couche(Network* network, int indice_couche, int type_couche, FILE* ptr); -// Lecture d'un réseau neuronal +// Lecture d'un réseau neuronal /* * Lit un réseau neuronal dans un fichier donné diff --git a/src/cnn/initialisation.c b/src/cnn/initialisation.c index b479ad8..276a0d4 100644 --- a/src/cnn/initialisation.c +++ b/src/cnn/initialisation.c @@ -13,9 +13,9 @@ void initialisation_1d_matrix(int initialisation, float* matrix, int dim, int n_ int n; if (initialisation == GLOROT) { n = (n_in + n_out)/2; - + } else if (initialisation == HE) { - n = n_in/2; + n = n_in/2; } else { printf_warning("Initialisation non reconnue dans 'initialisation_1d_matrix' \n"); return ; @@ -31,9 +31,9 @@ void initialisation_2d_matrix(int initialisation, float** matrix, int dim1, int int n; if (initialisation == GLOROT) { n = (n_in + n_out)/2; - + } else if (initialisation == HE) { - n = n_in/2; + n = n_in/2; } else { printf_warning("Initialisation non reconnue dans 'initialisation_2d_matrix' \n"); return ; @@ -51,9 +51,9 @@ void initialisation_3d_matrix(int initialisation, float*** matrix, int depth, in int n; if (initialisation == GLOROT) { n = (n_in + n_out)/2; - + } else if (initialisation == HE) { - n = n_in/2; + n = n_in/2; } else { printf_warning("Initialisation non reconnue dans 'initialisation_3d_matrix' \n"); return ; @@ -73,9 +73,9 @@ void initialisation_4d_matrix(int initialisation, float**** matrix, int depth1, int n; if (initialisation == GLOROT) { n = (n_in + n_out)/2; - + } else if (initialisation == HE) { - n = n_in/2; + n = n_in/2; } else { printf_warning("Initialisation non reconnue dans 'initialisation_3d_matrix' \n"); return ; diff --git a/src/cnn/jpeg.c b/src/cnn/jpeg.c index dd03f62..1b53bcb 100644 --- a/src/cnn/jpeg.c +++ b/src/cnn/jpeg.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -76,7 +76,7 @@ imgRawImage* loadJpegImageFile(char* lpFilename) { jpegDataset* loadJpegDataset(char* folderPath) { jpegDataset* dataset = (jpegDataset*)malloc(sizeof(jpegDataset)); imgRawImage* image; - + // We start by counting the number of images and categories dataset->numCategories = countDirectories(folderPath); dataset->numImages = countFiles(folderPath); @@ -128,7 +128,7 @@ jpegDataset* loadJpegDataset(char* folderPath) { dataset->width = image->width; dataset->height = image->height; dataset->numComponents = image->numComponents; - + free(image->lpData); free(image); diff --git a/src/cnn/matrix_multiplication.cu b/src/cnn/matrix_multiplication.cu index c331343..a35a262 100644 --- a/src/cnn/matrix_multiplication.cu +++ b/src/cnn/matrix_multiplication.cu @@ -40,12 +40,12 @@ void matrix_multiplication_device(float** m1, float** m2, float** result, int n, float* m1_dev; float* m2_dev; float* result_dev; - + gpuErrchk( cudaMallocPitch((void**)&m1_dev, &pitch_m1_dev, p * sizeof(float), n)); for (int i=0; i < n; i++) { gpuErrchk( cudaMemcpy((void*)((char*)m1_dev + i*pitch_m1_dev), (const void*)&(m1[i][0]), p*sizeof(float), cudaMemcpyHostToDevice)); } - + gpuErrchk( cudaMallocPitch((void**)&m2_dev, &pitch_m2_dev, q * sizeof(float), p)); for (int i=0; i < p; i++) { gpuErrchk( cudaMemcpy((void*)((char*)m2_dev + i*pitch_m2_dev), (const void*)&(m2[i][0]), q*sizeof(float), cudaMemcpyHostToDevice)); diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index 11fd105..fa6935b 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -201,7 +201,7 @@ Network* read_network(char* filename) { } } } - + fclose(ptr); return network; } @@ -214,7 +214,7 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) { kernel->nn = NULL; uint32_t buffer[5]; fread(&buffer, sizeof(buffer), 1, ptr); - + kernel->activation = buffer[0]; kernel->linearisation = buffer[1]; kernel->cnn->k_size = buffer[2]; diff --git a/src/cnn/test_network.c b/src/cnn/test_network.c index 70b778b..848789e 100644 --- a/src/cnn/test_network.c +++ b/src/cnn/test_network.c @@ -20,10 +20,10 @@ void test_network_mnist(Network* network, char* images_file, char* labels_file, // Load image int* mnist_parameters = read_mnist_images_parameters(images_file); - + int*** images = read_mnist_images(images_file); unsigned int* labels = read_mnist_labels(labels_file); - + nb_elem = mnist_parameters[0]; width = mnist_parameters[1]; diff --git a/src/cnn/train.c b/src/cnn/train.c index 87e6399..9e54086 100644 --- a/src/cnn/train.c +++ b/src/cnn/train.c @@ -125,7 +125,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di } else { network = read_network(recover); } - + shuffle_index = (int*)malloc(sizeof(int)*nb_images_total); for (int i=0; i < nb_images_total; i++) { @@ -141,7 +141,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di // Création des paramètres donnés à chaque thread dans le cas du multi-threading TrainParameters** train_parameters = (TrainParameters**)malloc(sizeof(TrainParameters*)*nb_threads); TrainParameters* param; - + for (int k=0; k < nb_threads; k++) { train_parameters[k] = (TrainParameters*)malloc(sizeof(TrainParameters)); param = train_parameters[k]; @@ -168,7 +168,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di // Cela est utile à des fins de débogage notamment, // où l'utilisation de threads rend vite les choses plus compliquées qu'elles ne le sont. TrainParameters* train_params = (TrainParameters*)malloc(sizeof(TrainParameters)); - + train_params->network = network; train_params->dataset_type = dataset_type; if (dataset_type == 0) { @@ -243,7 +243,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di accuracy += train_parameters[k]->accuracy / (float) nb_images_total; } } - + // On attend que tous les fils aient fini avant d'appliquer des modifications au réseau principal for (int k=0; k < nb_threads; k++) { if (train_parameters[k]->network) { // Si le fil a été utilisé @@ -264,15 +264,15 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di if (j == batches_epoques-1) { train_params->nb_images = nb_images_total - j*BATCHES; } - + train_thread((void*)train_params); - + accuracy += train_params->accuracy / (float) nb_images_total; current_accuracy = accuracy * nb_images_total/((j+1)*BATCHES); - + update_weights(network, network, train_params->nb_images); update_bias(network, network, train_params->nb_images); - + printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: "YELLOW"%0.4f%%"RESET" ", i, epochs, BATCHES*(j+1), nb_images_total, current_accuracy*100); fflush(stdout); #endif diff --git a/src/cnn/update.c b/src/cnn/update.c index 4848b9f..bd47e73 100644 --- a/src/cnn/update.c +++ b/src/cnn/update.c @@ -58,7 +58,7 @@ void update_weights(Network* network, Network* d_network, int nb_images) { } void update_bias(Network* network, Network* d_network, int nb_images) { - + int n = network->size; int output_width, output_depth; Kernel* k_i; diff --git a/src/cnn/utils.c b/src/cnn/utils.c index 601ec92..4c02c56 100644 --- a/src/cnn/utils.c +++ b/src/cnn/utils.c @@ -34,7 +34,7 @@ bool equals_networks(Network* network1, Network* network2) { checkEquals(size, "size", -1); checkEquals(initialisation, "initialisation", -1); checkEquals(dropout, "dropout", -1); - + for (int i=0; i < network1->size; i++) { checkEquals(width[i], "input_width", i); checkEquals(depth[i], "input_depth", i); @@ -166,7 +166,7 @@ Network* copy_network(Network* network) { k_size = network->kernel[i]->cnn->k_size; columns = network->kernel[i]->cnn->columns; output_dim = network->width[i+1]; - + network_cp->kernel[i]->nn = NULL; network_cp->kernel[i]->cnn = (Kernel_cnn*)malloc(sizeof(Kernel_cnn));