tipe/src/cnn/include/struct.h

82 lines
3.0 KiB
C
Raw Normal View History

2022-07-05 08:13:25 +02:00
#ifndef DEF_STRUCT_H
#define DEF_STRUCT_H
2023-03-27 18:17:50 +02:00
#include "config.h"
2023-03-08 20:48:34 +01:00
#define NO_POOLING 0
#define AVG_POOLING 1
#define MAX_POOLING 2
#define DOESNT_LINEARISE 0
#define DO_LINEARISE 1
2022-07-05 08:13:25 +02:00
typedef struct Kernel_cnn {
2023-02-19 13:54:00 +01:00
// Noyau ayant une couche matricielle en sortie
2023-05-14 14:09:40 +02:00
int k_size; // k_size = 2*padding + input_width + stride - output_width*stride
2023-02-19 13:54:00 +01:00
int rows; // Depth de l'input
int columns; // Depth de l'output
2023-05-14 14:09:40 +02:00
float*** bias; // bias[columns][output_width][output_width] <=> bias[output depth][output width][output width]
2023-05-13 17:22:47 +02:00
float*** d_bias; // d_bias[columns][output_width][output_width]
2023-03-27 18:17:50 +02:00
#ifdef ADAM_CNN_BIAS
2023-05-13 17:22:47 +02:00
float*** s_d_bias; // s_d_bias[columns][output_width][output_width]
float*** v_d_bias; // v_d_bias[columns][output_width][output_width]
2023-03-27 18:17:50 +02:00
#endif
2023-05-14 14:09:40 +02:00
float**** weights; // weights[rows][columns][k_size][k_size] <=> weights[input depth][output depth][kernel size][kernel size]
float**** d_weights; // d_weights[rows][columns][k_size][k_size]
2023-03-27 18:17:50 +02:00
#ifdef ADAM_CNN_WEIGHTS
float**** s_d_weights; // s_d_weights[rows][columns][k_size][k_size]
float**** v_d_weights; // v_d_weights[rows][columns][k_size][k_size]
2023-03-27 18:17:50 +02:00
#endif
2022-07-05 08:13:25 +02:00
} Kernel_cnn;
typedef struct Kernel_nn {
2023-02-19 13:54:00 +01:00
// Noyau ayant une couche vectorielle en sortie
2023-02-19 12:50:27 +01:00
int size_input; // Nombre d'éléments en entrée
2023-02-19 12:53:08 +01:00
int size_output; // Nombre d'éléments en sortie
2023-02-19 12:53:08 +01:00
float* bias; // bias[size_output]
float* d_bias; // d_bias[size_output]
2023-03-27 18:17:50 +02:00
#ifdef ADAM_DENSE_BIAS
float* s_d_bias; // s_d_bias[size_output]
float* v_d_bias; // v_d_bias[size_output]
2023-03-27 18:17:50 +02:00
#endif
2023-02-19 12:53:08 +01:00
float** weights; // weight[size_input][size_output]
float** d_weights; // d_weights[size_input][size_output]
2023-03-27 18:17:50 +02:00
#ifdef ADAM_DENSE_WEIGHTS
float** s_d_weights; // s_d_weights[size_input][size_output]
float** v_d_weights; // v_d_weights[size_input][size_output]
2023-03-27 18:17:50 +02:00
#endif
2022-07-05 08:13:25 +02:00
} Kernel_nn;
typedef struct Kernel {
2022-09-16 14:36:50 +02:00
Kernel_cnn* cnn; // NULL si ce n'est pas un cnn
Kernel_nn* nn; // NULL si ce n'est pas un nn
2023-02-19 13:54:00 +01:00
int activation; // Id de la fonction d'activation et -Id de sa dérivée
int linearisation; // 1 si c'est la linéarisation d'une couche, 0 sinon
2023-01-30 09:39:45 +01:00
int pooling; // 0 si pas pooling, 1 si average_pooling, 2 si max_pooling
int stride; // Valable uniquement une pooling et un cnn
int padding; // Valable uniquement une pooling et un cnn
2022-07-05 08:13:25 +02:00
} Kernel;
typedef struct Network{
2023-02-19 13:54:00 +01:00
int dropout; // Probabilité d'abandon d'un neurone dans [0, 100] (entiers)
2022-11-15 18:15:18 +01:00
float learning_rate; // Taux d'apprentissage du réseau
2023-02-19 13:54:00 +01:00
int initialisation; // Id du type d'initialisation
2022-09-16 14:36:50 +02:00
int max_size; // Taille du tableau contenant le réseau
int size; // Taille actuelle du réseau (size ≤ max_size)
2022-09-16 14:36:50 +02:00
int* width; // width[size]
int* depth; // depth[size]
2022-10-05 11:20:26 +02:00
Kernel** kernel; // kernel[size], contient tous les kernels
2023-02-19 13:54:00 +01:00
float**** input_z; // Tableau de toutes les couches du réseau input_z[size][couche->depth][couche->width][couche->width]
float**** input; // input[i] = f(input_z[i]) où f est la fonction d'activation de la couche i
2022-07-05 08:13:25 +02:00
} Network;
#endif