Remove white spaces

This commit is contained in:
augustin64 2023-01-17 15:34:29 +01:00
parent 7fdd869d6e
commit cea4132e2d
14 changed files with 57 additions and 61 deletions

View File

@ -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++) {

View File

@ -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++) {

View File

@ -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++) {

View File

@ -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);

View File

@ -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));

View File

@ -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é

View File

@ -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 ;

View File

@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <dirent.h>
#include <jerror.h>
#include <jpeglib.h>
@ -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);

View File

@ -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));

View File

@ -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];

View File

@ -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];

View File

@ -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

View File

@ -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;

View File

@ -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));