mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 15:16:26 +01:00
Update multithreading
This commit is contained in:
parent
18900f3fe9
commit
11ce67f845
@ -28,8 +28,8 @@ Network* create_network(int max_size, float learning_rate, int dropout, int init
|
||||
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);
|
||||
network->input_z[0] = NULL; // As we don't backpropagate the input
|
||||
create_a_cube_input_layer(network, 0, input_depth, input_dim);
|
||||
create_a_cube_input_z_layer(network, 0, input_depth, input_dim);
|
||||
return network;
|
||||
}
|
||||
|
||||
|
@ -193,13 +193,15 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
||||
}
|
||||
train_parameters[k]->network = copy_network(network);
|
||||
train_parameters[k]->start = BATCHES*j + (nb_images_total/BATCHES)*k;
|
||||
pthread_create( &tid[j], NULL, train_thread, (void*) train_parameters[k]);
|
||||
pthread_create( &tid[k], NULL, train_thread, (void*) train_parameters[k]);
|
||||
}
|
||||
for (int k=0; k < nb_threads; k++) {
|
||||
// On attend la terminaison de chaque thread un à un
|
||||
pthread_join( tid[j], NULL );
|
||||
pthread_join( tid[k], NULL );
|
||||
accuracy += train_parameters[k]->accuracy / (float) nb_images_total;
|
||||
// TODO patch_network(network, train_parameters[k]->network, train_parameters[k]->nb_images);
|
||||
|
||||
update_weights(network, train_parameters[k]->network);
|
||||
update_bias(network, train_parameters[k]->network);
|
||||
free_network(train_parameters[k]->network);
|
||||
}
|
||||
current_accuracy = accuracy * nb_images_total/((j+1)*BATCHES);
|
||||
|
@ -212,5 +212,19 @@ Network* copy_network(Network* network) {
|
||||
}
|
||||
}
|
||||
|
||||
network_cp->input_z = (float****)malloc(sizeof(float***)*size);
|
||||
for (int i=0; i < size; i++) { // input_z[size][couche->depth][couche->dim][couche->dim]
|
||||
network_cp->input_z[i] = (float***)malloc(sizeof(float**)*network->depth[i]);
|
||||
for (int j=0; j < network->depth[i]; j++) {
|
||||
network_cp->input_z[i][j] = (float**)malloc(sizeof(float*)*network->width[i]);
|
||||
for (int k=0; k < network->width[i]; k++) {
|
||||
network_cp->input_z[i][j][k] = (float*)malloc(sizeof(float)*network->width[i]);
|
||||
for (int l=0; l < network->width[i]; l++) {
|
||||
network_cp->input_z[i][j][k][l] = 0.;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return network_cp;
|
||||
}
|
@ -210,7 +210,7 @@ void train(int epochs, int layers, int neurons, char* recovery, char* image_file
|
||||
pthread_create( &tid[j], NULL, train_thread, (void*) train_parameters[j]);
|
||||
}
|
||||
for(int j=0; j < nb_threads; j++ ) {
|
||||
// On join les threads créés sur le CPU
|
||||
// On récupère les threads créés sur le CPU
|
||||
pthread_join( tid[j], NULL );
|
||||
|
||||
accuracy += train_parameters[j]->accuracy / (float) nb_images_total;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../src/cnn/include/neuron_io.h"
|
||||
#include "../src/cnn/include/creation.h"
|
||||
#include "../src/cnn/include/utils.h"
|
||||
#include "../src/cnn/include/free.h"
|
||||
#include "../src/include/colors.h"
|
||||
|
||||
|
||||
@ -30,5 +31,10 @@ int main() {
|
||||
}
|
||||
printf(GREEN "OK\n" RESET);
|
||||
|
||||
printf("Libération de la mémoire\n");
|
||||
free_network(network);
|
||||
free_network(network2);
|
||||
printf(GREEN "OK\n" RESET);
|
||||
|
||||
return 0;
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include "../src/include/colors.h"
|
||||
#include "../src/cnn/include/creation.h"
|
||||
#include "../src/cnn/include/utils.h"
|
||||
#include "../src/cnn/include/free.h"
|
||||
#include "../src/include/colors.h"
|
||||
|
||||
int main() {
|
||||
@ -22,5 +23,7 @@ int main() {
|
||||
}
|
||||
printf(GREEN "OK\n" RESET);
|
||||
|
||||
free_network(network_cp);
|
||||
free_network(network);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user