Add of the dropout feature

This commit is contained in:
julienChemillier 2022-11-04 12:02:00 +01:00
parent 682715d5d7
commit b21ac23673
2 changed files with 22 additions and 0 deletions

View File

@ -57,6 +57,12 @@ void forward_propagation(Network* network) {
output_width = network->width[i+1]; output_width = network->width[i+1];
activation = k_i->activation; activation = k_i->activation;
if (k_i->nn) {
drop_neurones(input, 1, 1, input_width, network->dropout);
} else {
drop_neurones(input, input_depth, input_width, input_width, network->dropout);
}
if (k_i->cnn) { // Convolution if (k_i->cnn) { // Convolution
make_convolution(k_i->cnn, input, output, output_width); make_convolution(k_i->cnn, input, output, output_width);
copy_input_to_input_z(output, output_a, output_depth, output_width, output_width); copy_input_to_input_z(output, output_a, output_depth, output_width, output_width);
@ -125,6 +131,17 @@ void backward_propagation(Network* network, float wanted_number) {
free(wanted_output); free(wanted_output);
} }
void drop_neurones(float*** input, int depth, int dim1, int dim2, int dropout) {
for (int i=0; i<depth; i++) {
for (int j=0; j<dim1; j++) {
for (int k=0; k<dim2; k++) {
if (will_be_drop(dropout))
input[i][j][k] = 0;
}
}
}
}
void copy_input_to_input_z(float*** output, float*** output_a, int output_depth, int output_rows, int output_columns) { void copy_input_to_input_z(float*** output, float*** output_a, int output_depth, int output_rows, int output_columns) {
for (int i=0; i<output_depth; i++) { for (int i=0; i<output_depth; i++) {
for (int j=0; j<output_rows; j++) { for (int j=0; j<output_rows; j++) {

View File

@ -24,6 +24,11 @@ void forward_propagation(Network* network);
*/ */
void backward_propagation(Network* network, float wanted_number); void backward_propagation(Network* network, float wanted_number);
/*
* Met à 0 chaque valeur de l'input avec une probabilité de dropout %
*/
void drop_neurones(float*** input, int depth, int dim1, int dim2, int dropout);
/* /*
* Copie les données de output dans output_a (Sachant que les deux matrices ont les mêmes dimensions) * Copie les données de output dans output_a (Sachant que les deux matrices ont les mêmes dimensions)
*/ */