mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 23:26:25 +01:00
This workaround seems better
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34
This commit is contained in:
parent
cdbabd21be
commit
c9a890a20a
@ -151,19 +151,19 @@ Network* read_network(char* filename) {
|
|||||||
uint32_t dropout;
|
uint32_t dropout;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
(void)fread(&magic, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic, sizeof(uint32_t), 1, ptr);
|
||||||
if (magic != MAGIC_NUMBER) {
|
if (magic != MAGIC_NUMBER) {
|
||||||
printf_error("Incorrect magic number !\n");
|
printf_error("Incorrect magic number !\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lecture des constantes du réseau
|
// Lecture des constantes du réseau
|
||||||
(void)fread(&size, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&size, sizeof(uint32_t), 1, ptr);
|
||||||
network->size = size;
|
network->size = size;
|
||||||
network->max_size = size;
|
network->max_size = size;
|
||||||
(void)fread(&initialisation, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&initialisation, sizeof(uint32_t), 1, ptr);
|
||||||
network->initialisation = initialisation;
|
network->initialisation = initialisation;
|
||||||
(void)fread(&dropout, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&dropout, sizeof(uint32_t), 1, ptr);
|
||||||
network->dropout = dropout;
|
network->dropout = dropout;
|
||||||
|
|
||||||
// Lecture de la taille de l'entrée des différentes matrices
|
// Lecture de la taille de l'entrée des différentes matrices
|
||||||
@ -171,9 +171,9 @@ Network* read_network(char* filename) {
|
|||||||
network->depth = (int*)nalloc(size, sizeof(int));
|
network->depth = (int*)nalloc(size, sizeof(int));
|
||||||
|
|
||||||
for (int i=0; i < (int)size; i++) {
|
for (int i=0; i < (int)size; i++) {
|
||||||
(void)fread(&tmp, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&tmp, sizeof(uint32_t), 1, ptr);
|
||||||
network->width[i] = tmp;
|
network->width[i] = tmp;
|
||||||
(void)fread(&tmp, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&tmp, sizeof(uint32_t), 1, ptr);
|
||||||
network->depth[i] = tmp;
|
network->depth[i] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ Network* read_network(char* filename) {
|
|||||||
uint32_t type_couche[size-1];
|
uint32_t type_couche[size-1];
|
||||||
|
|
||||||
for (int i=0; i < (int)size-1; i++) {
|
for (int i=0; i < (int)size-1; i++) {
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
type_couche[i] = tmp;
|
type_couche[i] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
|||||||
kernel->cnn = (Kernel_cnn*)nalloc(1, sizeof(Kernel_cnn));
|
kernel->cnn = (Kernel_cnn*)nalloc(1, sizeof(Kernel_cnn));
|
||||||
kernel->nn = NULL;
|
kernel->nn = NULL;
|
||||||
uint32_t buffer[5];
|
uint32_t buffer[5];
|
||||||
(void)fread(&buffer, sizeof(buffer), 1, ptr);
|
(void) !fread(&buffer, sizeof(buffer), 1, ptr);
|
||||||
|
|
||||||
kernel->activation = buffer[0];
|
kernel->activation = buffer[0];
|
||||||
kernel->linearisation = buffer[1];
|
kernel->linearisation = buffer[1];
|
||||||
@ -252,7 +252,7 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
|||||||
cnn->bias[i][j] = (float*)nalloc(output_dim, sizeof(float));
|
cnn->bias[i][j] = (float*)nalloc(output_dim, sizeof(float));
|
||||||
cnn->d_bias[i][j] = (float*)nalloc(output_dim, sizeof(float));
|
cnn->d_bias[i][j] = (float*)nalloc(output_dim, sizeof(float));
|
||||||
for (int k=0; k < output_dim; k++) {
|
for (int k=0; k < output_dim; k++) {
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
cnn->bias[i][j][k] = tmp;
|
cnn->bias[i][j][k] = tmp;
|
||||||
cnn->d_bias[i][j][k] = 0.;
|
cnn->d_bias[i][j][k] = 0.;
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
|||||||
cnn->weights[i][j][k] = (float*)nalloc(cnn->k_size, sizeof(float));
|
cnn->weights[i][j][k] = (float*)nalloc(cnn->k_size, sizeof(float));
|
||||||
cnn->d_weights[i][j][k] = (float*)nalloc(cnn->k_size, sizeof(float));
|
cnn->d_weights[i][j][k] = (float*)nalloc(cnn->k_size, sizeof(float));
|
||||||
for (int l=0; l < cnn->k_size; l++) {
|
for (int l=0; l < cnn->k_size; l++) {
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
cnn->weights[i][j][k][l] = tmp;
|
cnn->weights[i][j][k][l] = tmp;
|
||||||
cnn->d_weights[i][j][k][l] = 0.;
|
cnn->d_weights[i][j][k][l] = 0.;
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
|||||||
kernel->nn = (Kernel_nn*)nalloc(1, sizeof(Kernel_nn));
|
kernel->nn = (Kernel_nn*)nalloc(1, sizeof(Kernel_nn));
|
||||||
kernel->cnn = NULL;
|
kernel->cnn = NULL;
|
||||||
uint32_t buffer[4];
|
uint32_t buffer[4];
|
||||||
(void)fread(&buffer, sizeof(buffer), 1, ptr);
|
(void) !fread(&buffer, sizeof(buffer), 1, ptr);
|
||||||
|
|
||||||
kernel->activation = buffer[0];
|
kernel->activation = buffer[0];
|
||||||
kernel->linearisation = buffer[1];
|
kernel->linearisation = buffer[1];
|
||||||
@ -297,7 +297,7 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
|||||||
nn->bias = (float*)nalloc(nn->size_output, sizeof(float));
|
nn->bias = (float*)nalloc(nn->size_output, sizeof(float));
|
||||||
nn->d_bias = (float*)nalloc(nn->size_output, sizeof(float));
|
nn->d_bias = (float*)nalloc(nn->size_output, sizeof(float));
|
||||||
for (int i=0; i < nn->size_output; i++) {
|
for (int i=0; i < nn->size_output; i++) {
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
nn->bias[i] = tmp;
|
nn->bias[i] = tmp;
|
||||||
nn->d_bias[i] = 0.;
|
nn->d_bias[i] = 0.;
|
||||||
}
|
}
|
||||||
@ -308,15 +308,15 @@ Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
|||||||
nn->weights[i] = (float*)nalloc(nn->size_output, sizeof(float));
|
nn->weights[i] = (float*)nalloc(nn->size_output, sizeof(float));
|
||||||
nn->d_weights[i] = (float*)nalloc(nn->size_output, sizeof(float));
|
nn->d_weights[i] = (float*)nalloc(nn->size_output, sizeof(float));
|
||||||
for (int j=0; j < nn->size_output; j++) {
|
for (int j=0; j < nn->size_output; j++) {
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
nn->weights[i][j] = tmp;
|
nn->weights[i][j] = tmp;
|
||||||
nn->d_weights[i][j] = 0.;
|
nn->d_weights[i][j] = 0.;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type_couche == 2) { // Cas du Pooling Layer
|
} else if (type_couche == 2) { // Cas du Pooling Layer
|
||||||
uint32_t pooling, linearisation;
|
uint32_t pooling, linearisation;
|
||||||
(void)fread(&linearisation, sizeof(linearisation), 1, ptr);
|
(void) !fread(&linearisation, sizeof(linearisation), 1, ptr);
|
||||||
(void)fread(&pooling, sizeof(pooling), 1, ptr);
|
(void) !fread(&pooling, sizeof(pooling), 1, ptr);
|
||||||
|
|
||||||
kernel->cnn = NULL;
|
kernel->cnn = NULL;
|
||||||
kernel->nn = NULL;
|
kernel->nn = NULL;
|
||||||
|
@ -15,7 +15,7 @@ int** read_image(unsigned int width, unsigned int height, FILE* ptr) {
|
|||||||
|
|
||||||
size_t line_size = sizeof(int) * width;
|
size_t line_size = sizeof(int) * width;
|
||||||
|
|
||||||
(void)fread(buffer, sizeof(buffer), 1, ptr);
|
(void) !fread(buffer, sizeof(buffer), 1, ptr);
|
||||||
|
|
||||||
for (int i=0; i < (int)height; i++) {
|
for (int i=0; i < (int)height; i++) {
|
||||||
int* line = (int*)malloc(line_size);
|
int* line = (int*)malloc(line_size);
|
||||||
@ -39,7 +39,7 @@ int* read_mnist_images_parameters(char* filename) {
|
|||||||
unsigned int height;
|
unsigned int height;
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
|
|
||||||
(void)fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||||
magic_number = swap_endian(magic_number);
|
magic_number = swap_endian(magic_number);
|
||||||
|
|
||||||
if (magic_number != 2051) {
|
if (magic_number != 2051) {
|
||||||
@ -47,13 +47,13 @@ int* read_mnist_images_parameters(char* filename) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
||||||
tab[0] = swap_endian(number_of_images);
|
tab[0] = swap_endian(number_of_images);
|
||||||
|
|
||||||
(void)fread(&height, sizeof(unsigned int), 1, ptr);
|
(void) !fread(&height, sizeof(unsigned int), 1, ptr);
|
||||||
tab[1] = swap_endian(height);
|
tab[1] = swap_endian(height);
|
||||||
|
|
||||||
(void)fread(&width, sizeof(unsigned int), 1, ptr);
|
(void) !fread(&width, sizeof(unsigned int), 1, ptr);
|
||||||
tab[2] = swap_endian(width);
|
tab[2] = swap_endian(width);
|
||||||
|
|
||||||
return tab;
|
return tab;
|
||||||
@ -68,7 +68,7 @@ uint32_t read_mnist_labels_nb_images(char* filename) {
|
|||||||
uint32_t magic_number;
|
uint32_t magic_number;
|
||||||
uint32_t number_of_images;
|
uint32_t number_of_images;
|
||||||
|
|
||||||
(void)fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||||
magic_number = swap_endian(magic_number);
|
magic_number = swap_endian(magic_number);
|
||||||
|
|
||||||
if (magic_number != 2049) {
|
if (magic_number != 2049) {
|
||||||
@ -76,7 +76,7 @@ uint32_t read_mnist_labels_nb_images(char* filename) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
||||||
number_of_images = swap_endian(number_of_images);
|
number_of_images = swap_endian(number_of_images);
|
||||||
|
|
||||||
return number_of_images;
|
return number_of_images;
|
||||||
@ -93,7 +93,7 @@ int*** read_mnist_images(char* filename) {
|
|||||||
unsigned int height;
|
unsigned int height;
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
|
|
||||||
(void)fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||||
magic_number = swap_endian(magic_number);
|
magic_number = swap_endian(magic_number);
|
||||||
|
|
||||||
if (magic_number != 2051) {
|
if (magic_number != 2051) {
|
||||||
@ -101,13 +101,13 @@ int*** read_mnist_images(char* filename) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&number_of_images, sizeof(uint32_t), 1, ptr);
|
||||||
number_of_images = swap_endian(number_of_images);
|
number_of_images = swap_endian(number_of_images);
|
||||||
|
|
||||||
(void)fread(&height, sizeof(unsigned int), 1, ptr);
|
(void) !fread(&height, sizeof(unsigned int), 1, ptr);
|
||||||
height = swap_endian(height);
|
height = swap_endian(height);
|
||||||
|
|
||||||
(void)fread(&width, sizeof(unsigned int), 1, ptr);
|
(void) !fread(&width, sizeof(unsigned int), 1, ptr);
|
||||||
width = swap_endian(width);
|
width = swap_endian(width);
|
||||||
|
|
||||||
int*** tab = (int***)malloc(sizeof(int**)*number_of_images);
|
int*** tab = (int***)malloc(sizeof(int**)*number_of_images);
|
||||||
@ -127,7 +127,7 @@ unsigned int* read_mnist_labels(char* filename) {
|
|||||||
uint32_t magic_number;
|
uint32_t magic_number;
|
||||||
uint32_t number_of_items;
|
uint32_t number_of_items;
|
||||||
|
|
||||||
(void)fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||||
magic_number = swap_endian(magic_number);
|
magic_number = swap_endian(magic_number);
|
||||||
|
|
||||||
if (magic_number != 2049) {
|
if (magic_number != 2049) {
|
||||||
@ -135,11 +135,11 @@ unsigned int* read_mnist_labels(char* filename) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fread(&number_of_items, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&number_of_items, sizeof(uint32_t), 1, ptr);
|
||||||
number_of_items = swap_endian(number_of_items);
|
number_of_items = swap_endian(number_of_items);
|
||||||
|
|
||||||
unsigned char buffer[number_of_items];
|
unsigned char buffer[number_of_items];
|
||||||
(void)fread(buffer, sizeof(unsigned char), number_of_items, ptr);
|
(void) !fread(buffer, sizeof(unsigned char), number_of_items, ptr);
|
||||||
|
|
||||||
unsigned int* labels = (unsigned int*)malloc(sizeof(unsigned int)*number_of_items);
|
unsigned int* labels = (unsigned int*)malloc(sizeof(unsigned int)*number_of_items);
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
|||||||
float bias;
|
float bias;
|
||||||
float tmp;
|
float tmp;
|
||||||
|
|
||||||
(void)fread(&activation, sizeof(float), 1, ptr);
|
(void) !fread(&activation, sizeof(float), 1, ptr);
|
||||||
(void)fread(&bias, sizeof(float), 1, ptr);
|
(void) !fread(&bias, sizeof(float), 1, ptr);
|
||||||
|
|
||||||
neuron->bias = bias;
|
neuron->bias = bias;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
|||||||
neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
|
neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||||
|
|
||||||
for (int i=0; i < (int)nb_weights; i++) {
|
for (int i=0; i < (int)nb_weights; i++) {
|
||||||
(void)fread(&tmp, sizeof(float), 1, ptr);
|
(void) !fread(&tmp, sizeof(float), 1, ptr);
|
||||||
neuron->weights[i] = tmp;
|
neuron->weights[i] = tmp;
|
||||||
neuron->back_weights[i] = 0.0;
|
neuron->back_weights[i] = 0.0;
|
||||||
neuron->last_back_weights[i] = 0.0;
|
neuron->last_back_weights[i] = 0.0;
|
||||||
@ -60,13 +60,13 @@ Network* read_network(char* filename) {
|
|||||||
uint32_t nb_layers;
|
uint32_t nb_layers;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
(void)fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||||
if (magic_number != MAGIC_NUMBER) {
|
if (magic_number != MAGIC_NUMBER) {
|
||||||
printf("Incorrect magic number !\n");
|
printf("Incorrect magic number !\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fread(&nb_layers, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&nb_layers, sizeof(uint32_t), 1, ptr);
|
||||||
network->nb_layers = nb_layers;
|
network->nb_layers = nb_layers;
|
||||||
|
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ Network* read_network(char* filename) {
|
|||||||
|
|
||||||
for (int i=0; i < (int)nb_layers; i++) {
|
for (int i=0; i < (int)nb_layers; i++) {
|
||||||
layers[i] = (Layer*)malloc(sizeof(Layer));
|
layers[i] = (Layer*)malloc(sizeof(Layer));
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
layers[i]->nb_neurons = tmp;
|
layers[i]->nb_neurons = tmp;
|
||||||
nb_neurons_layer[i] = tmp;
|
nb_neurons_layer[i] = tmp;
|
||||||
}
|
}
|
||||||
@ -137,8 +137,8 @@ Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr) {
|
|||||||
float back_bias;
|
float back_bias;
|
||||||
float tmp;
|
float tmp;
|
||||||
|
|
||||||
(void)fread(&activation, sizeof(float), 1, ptr);
|
(void) !fread(&activation, sizeof(float), 1, ptr);
|
||||||
(void)fread(&back_bias, sizeof(float), 1, ptr);
|
(void) !fread(&back_bias, sizeof(float), 1, ptr);
|
||||||
|
|
||||||
neuron->bias = 0.0;
|
neuron->bias = 0.0;
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr) {
|
|||||||
neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
|
neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||||
|
|
||||||
for (int i=0; i < (int)nb_weights; i++) {
|
for (int i=0; i < (int)nb_weights; i++) {
|
||||||
(void)fread(&tmp, sizeof(float), 1, ptr);
|
(void) !fread(&tmp, sizeof(float), 1, ptr);
|
||||||
neuron->weights[i] = 0.0;
|
neuron->weights[i] = 0.0;
|
||||||
neuron->back_weights[i] = tmp;
|
neuron->back_weights[i] = tmp;
|
||||||
neuron->last_back_weights[i] = 0.0;
|
neuron->last_back_weights[i] = 0.0;
|
||||||
@ -179,13 +179,13 @@ Network* read_delta_network(char* filename) {
|
|||||||
uint32_t nb_layers;
|
uint32_t nb_layers;
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
(void)fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&magic_number, sizeof(uint32_t), 1, ptr);
|
||||||
if (magic_number != DELTA_MAGIC_NUMBER) {
|
if (magic_number != DELTA_MAGIC_NUMBER) {
|
||||||
printf("Incorrect magic number !\n");
|
printf("Incorrect magic number !\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fread(&nb_layers, sizeof(uint32_t), 1, ptr);
|
(void) !fread(&nb_layers, sizeof(uint32_t), 1, ptr);
|
||||||
network->nb_layers = nb_layers;
|
network->nb_layers = nb_layers;
|
||||||
|
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ Network* read_delta_network(char* filename) {
|
|||||||
|
|
||||||
for (int i=0; i < (int)nb_layers; i++) {
|
for (int i=0; i < (int)nb_layers; i++) {
|
||||||
layers[i] = (Layer*)malloc(sizeof(Layer));
|
layers[i] = (Layer*)malloc(sizeof(Layer));
|
||||||
(void)fread(&tmp, sizeof(tmp), 1, ptr);
|
(void) !fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
layers[i]->nb_neurons = tmp;
|
layers[i]->nb_neurons = tmp;
|
||||||
nb_neurons_layer[i] = tmp;
|
nb_neurons_layer[i] = tmp;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user