mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 23:26:25 +01:00
Merge branch 'main' of https://github.com/julienChemillier/TIPE
This commit is contained in:
commit
9d77080de7
4
.github/workflows/tests.yml
vendored
4
.github/workflows/tests.yml
vendored
@ -13,8 +13,8 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: print versions
|
||||
run: make --version; gcc --version
|
||||
- name: make all
|
||||
run: make all
|
||||
- name: run-tests
|
||||
run: make run-tests
|
||||
- name: mnist main train
|
||||
|
@ -20,7 +20,7 @@ void write_network(char* filename, Network* network);
|
||||
/*
|
||||
* Écrit une couche dans le fichier spécifié par le pointeur ptr
|
||||
*/
|
||||
void write_couche(Kernel* kernel, int type_couche, FILE* ptr);
|
||||
void write_couche(Network* network, int indice_couche, int type_couche, FILE* ptr);
|
||||
|
||||
|
||||
// Lecture d'un réseau neuronal
|
||||
@ -33,5 +33,5 @@ Network* read_network(char* filename);
|
||||
/*
|
||||
* Lit une kernel dans le fichier spécifié par le pointeur ptr
|
||||
*/
|
||||
Kernel* read_kernel(int type_couche, FILE* ptr);
|
||||
Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr);
|
||||
#endif
|
@ -47,17 +47,19 @@ void write_network(char* filename, Network* network) {
|
||||
|
||||
// Écriture du pré-corps et corps
|
||||
for (int i=0; i < size; i++) {
|
||||
write_couche(network->kernel[i], type_couche[i], ptr);
|
||||
write_couche(network, i, type_couche[i], ptr);
|
||||
}
|
||||
|
||||
fclose(ptr);
|
||||
}
|
||||
|
||||
|
||||
void write_couche(Kernel* kernel, int type_couche, FILE* ptr) {
|
||||
void write_couche(Network* network, int indice_couche, int type_couche, FILE* ptr) {
|
||||
Kernel* kernel = network->kernel[indice_couche];
|
||||
int indice_buffer = 0;
|
||||
if (type_couche == 0) { // Cas du CNN
|
||||
Kernel_cnn* cnn = kernel->cnn;
|
||||
int output_dim = network->width[indice_couche];
|
||||
|
||||
// Écriture du pré-corps
|
||||
uint32_t pre_buffer[4];
|
||||
@ -68,11 +70,12 @@ void write_couche(Kernel* kernel, int type_couche, FILE* ptr) {
|
||||
fwrite(pre_buffer, sizeof(pre_buffer), 1, ptr);
|
||||
|
||||
// Écriture du corps
|
||||
float buffer[cnn->k_size*cnn->k_size*cnn->columns*(cnn->rows+1)];
|
||||
float buffer[cnn->columns*(cnn->k_size*cnn->k_size*cnn->rows+output_dim*output_dim)];
|
||||
|
||||
for (int i=0; i < cnn->columns; i++) {
|
||||
for (int j=0; j < cnn->k_size; j++) {
|
||||
for (int k=0; k < cnn->k_size; k++) {
|
||||
for (int j=0; j < output_dim; j++) {
|
||||
for (int k=0; k < output_dim; k++) {
|
||||
printf("%f\n", cnn->bias[i][j][k]);
|
||||
bufferAdd(cnn->bias[i][j][k]);
|
||||
}
|
||||
}
|
||||
@ -166,7 +169,7 @@ Network* read_network(char* filename) {
|
||||
network->kernel = (Kernel**)malloc(sizeof(Kernel*)*size);
|
||||
|
||||
for (int i=0; i < (int)size; i++) {
|
||||
network->kernel[i] = read_kernel(type_couche[i], ptr);
|
||||
network->kernel[i] = read_kernel(type_couche[i], network->width[i], ptr);
|
||||
}
|
||||
|
||||
network->input = (float****)malloc(sizeof(float***)*size);
|
||||
@ -187,7 +190,7 @@ Network* read_network(char* filename) {
|
||||
return network;
|
||||
}
|
||||
|
||||
Kernel* read_kernel(int type_couche, FILE* ptr) {
|
||||
Kernel* read_kernel(int type_couche, int output_dim, FILE* ptr) {
|
||||
Kernel* kernel = (Kernel*)malloc(sizeof(Kernel));
|
||||
if (type_couche == 0) { // Cas du CNN
|
||||
// Lecture du "Pré-corps"
|
||||
@ -209,12 +212,12 @@ Kernel* read_kernel(int type_couche, FILE* ptr) {
|
||||
cnn->bias = (float***)malloc(sizeof(float**)*cnn->columns);
|
||||
cnn->d_bias = (float***)malloc(sizeof(float**)*cnn->columns);
|
||||
for (int i=0; i < cnn->columns; i++) {
|
||||
cnn->bias[i] = (float**)malloc(sizeof(float*)*cnn->k_size);
|
||||
cnn->d_bias[i] = (float**)malloc(sizeof(float*)*cnn->k_size);
|
||||
for (int j=0; j < cnn->k_size; j++) {
|
||||
cnn->bias[i][j] = (float*)malloc(sizeof(float)*cnn->k_size);
|
||||
cnn->d_bias[i][j] = (float*)malloc(sizeof(float)*cnn->k_size);
|
||||
for (int k=0; k < cnn->k_size; k++) {
|
||||
cnn->bias[i] = (float**)malloc(sizeof(float*)*output_dim);
|
||||
cnn->d_bias[i] = (float**)malloc(sizeof(float*)*output_dim);
|
||||
for (int j=0; j < output_dim; j++) {
|
||||
cnn->bias[i][j] = (float*)malloc(sizeof(float)*output_dim);
|
||||
cnn->d_bias[i][j] = (float*)malloc(sizeof(float)*output_dim);
|
||||
for (int k=0; k < output_dim; k++) {
|
||||
fread(&tmp, sizeof(tmp), 1, ptr);
|
||||
cnn->bias[i][j][k] = tmp;
|
||||
cnn->d_bias[i][j][k] = 0.;
|
||||
|
@ -12,12 +12,13 @@
|
||||
if (network1->var != network2->var) { \
|
||||
printf_error("network1->" name " et network2->" name " ne sont pas égaux\n"); \
|
||||
if (indice != -1) { \
|
||||
printf(BOLDBLUE"[ INFO_ ]"RESET" indice: %d\n", indice); \
|
||||
printf(BOLDBLUE"[ INFO_ ]" RESET " indice: %d\n", indice); \
|
||||
} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
bool equals_networks(Network* network1, Network* network2) {
|
||||
int output_dim;
|
||||
checkEquals(size, "size", -1);
|
||||
checkEquals(initialisation, "initialisation", -1);
|
||||
checkEquals(dropout, "dropout", -1);
|
||||
@ -50,12 +51,13 @@ bool equals_networks(Network* network1, Network* network2) {
|
||||
}
|
||||
} else {
|
||||
// Type CNN
|
||||
output_dim = network1->width[i];
|
||||
checkEquals(kernel[i]->cnn->k_size, "kernel[i]->k_size", i);
|
||||
checkEquals(kernel[i]->cnn->rows, "kernel[i]->rows", i);
|
||||
checkEquals(kernel[i]->cnn->columns, "kernel[i]->columns", i);
|
||||
for (int j=0; j < network1->kernel[i]->cnn->columns; j++) {
|
||||
for (int k=0; k < network1->kernel[i]->cnn->k_size; k++) {
|
||||
for (int l=0; l < network1->kernel[i]->cnn->k_size; l++) {
|
||||
for (int k=0; k < output_dim; k++) {
|
||||
for (int l=0; l < output_dim; l++) {
|
||||
checkEquals(kernel[i]->cnn->bias[j][k][l], "kernel[i]->cnn->bias[j][k][l]", l);
|
||||
}
|
||||
}
|
||||
@ -87,6 +89,7 @@ Network* copy_network(Network* network) {
|
||||
int rows;
|
||||
int k_size;
|
||||
int columns;
|
||||
int output_dim;
|
||||
|
||||
copyVar(dropout);
|
||||
copyVar(learning_rate);
|
||||
@ -149,6 +152,8 @@ Network* copy_network(Network* network) {
|
||||
rows = network->kernel[i]->cnn->rows;
|
||||
k_size = network->kernel[i]->cnn->k_size;
|
||||
columns = network->kernel[i]->cnn->columns;
|
||||
output_dim = network->width[i];
|
||||
|
||||
|
||||
network_cp->kernel[i]->nn = NULL;
|
||||
network_cp->kernel[i]->cnn = (Kernel_cnn*)malloc(sizeof(Kernel_cnn));
|
||||
@ -160,12 +165,12 @@ Network* copy_network(Network* network) {
|
||||
network_cp->kernel[i]->cnn->bias = (float***)malloc(sizeof(float**)*columns);
|
||||
network_cp->kernel[i]->cnn->d_bias = (float***)malloc(sizeof(float**)*columns);
|
||||
for (int j=0; j < columns; j++) {
|
||||
network_cp->kernel[i]->cnn->bias[j] = (float**)malloc(sizeof(float*)*k_size);
|
||||
network_cp->kernel[i]->cnn->d_bias[j] = (float**)malloc(sizeof(float*)*k_size);
|
||||
for (int k=0; k < k_size; k++) {
|
||||
network_cp->kernel[i]->cnn->bias[j][k] = (float*)malloc(sizeof(float)*k_size);
|
||||
network_cp->kernel[i]->cnn->d_bias[j][k] = (float*)malloc(sizeof(float)*k_size);
|
||||
for (int l=0; l < k_size; l++) {
|
||||
network_cp->kernel[i]->cnn->bias[j] = (float**)malloc(sizeof(float*)*output_dim);
|
||||
network_cp->kernel[i]->cnn->d_bias[j] = (float**)malloc(sizeof(float*)*output_dim);
|
||||
for (int k=0; k < output_dim; k++) {
|
||||
network_cp->kernel[i]->cnn->bias[j][k] = (float*)malloc(sizeof(float)*output_dim);
|
||||
network_cp->kernel[i]->cnn->d_bias[j][k] = (float*)malloc(sizeof(float)*output_dim);
|
||||
for (int l=0; l < output_dim; l++) {
|
||||
copyVar(kernel[i]->cnn->bias[j][k][l]);
|
||||
network_cp->kernel[i]->cnn->d_bias[j][k][l] = 0.;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void count_labels(char* filename) {
|
||||
}
|
||||
|
||||
for (int i=0; i < 10; i++) {
|
||||
printf("Nombre de %d: %x\n", i, tab[i]);
|
||||
printf("Nombre de %d: %u\n", i, tab[i]);
|
||||
}
|
||||
free(labels);
|
||||
}
|
||||
|
@ -3,14 +3,15 @@
|
||||
set -e
|
||||
|
||||
OUT="build"
|
||||
[[ -f "$OUT/mnist-utils" ]] || make $OUT/mnist-utils
|
||||
make $OUT/mnist-utils
|
||||
|
||||
echo "Compte des labels"
|
||||
"$OUT/mnist-utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte > /dev/null
|
||||
"$OUT/mnist-utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte
|
||||
echo "OK"
|
||||
|
||||
echo "Création du réseau"
|
||||
"$OUT/mnist-utils" creer-reseau -n 3 -o .test-cache/reseau.bin > /dev/null
|
||||
mkdir -p .test-cache
|
||||
"$OUT/mnist-utils" creer-reseau -n 3 -o .test-cache/reseau.bin
|
||||
echo "OK"
|
||||
|
||||
echo "Affichage poids"
|
||||
|
Loading…
Reference in New Issue
Block a user