This commit is contained in:
augustin64 2022-04-11 19:57:09 +02:00
parent 1b2cb44df0
commit a16aec693c
2 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include "neural_network.c"
#include "neuron_io.c"
@ -9,7 +10,7 @@
int indice_max(float* tab, int n) {
int indice = -1;
float maxi = 0.;
float maxi = FLT_MIN;
for (int i=0; i < n; i++) {
if (tab[i] > maxi) {
@ -96,7 +97,7 @@ void train(int batches, int couches, int neurons, char* recovery, char* image_fi
forward_propagation(reseau);
for (int k=0; k < nb_neurones_der; k++) {
sortie[k] = der_couche->neurones[k]->activation;
sortie[k] = der_couche->neurones[k]->z;
}
if (indice_max(sortie, nb_neurones_der) == labels[j]) {
accuracy += 1. / (float)nb_images;
@ -137,13 +138,13 @@ void recognize(char* modele, char* entree, char* sortie) {
for (int j=0; j < derniere_couche->nb_neurones; j++) {
if (! strcmp(sortie, "json")) {
printf("%f", derniere_couche->neurones[j]->activation); // CHECK: ->activation ou ->z
printf("%f", derniere_couche->neurones[j]->z);
if (j+1 < derniere_couche->nb_neurones) {
printf(", ");
}
} else
printf("Probabilité %d: %f\n", j, derniere_couche->neurones[j]->activation); // CHECK: ->activation ou ->z
printf("Probabilité %d: %f\n", j, derniere_couche->neurones[j]->z);
}
if (! strcmp(sortie, "json")) {
if (i+1 < nb_images) {

View File

@ -38,7 +38,7 @@ function draw(ctx, x, y, isDown) {
ctx.beginPath();
// On choisit les options suivantes:
ctx.strokeStyle = "white";
ctx.lineWidth = "10";
ctx.lineWidth = "12";
ctx.lineJoin = "round";
ctx.lineCap = "round";
ctx.moveTo(lastX, lastY);
@ -126,10 +126,10 @@ function getPrediction() {
let tableau = [];
let tmp_tableau = [];
while (curWidth < totalWidth) {
curHeight = 0;
while (curHeight < totalHeight) {
curWidth = 0;
tmp_tableau = [];
while (curHeight < totalHeight) {
while (curWidth < totalWidth) {
data = ctx.getImageData(curWidth, curHeight, stepSize, stepSize);
size = data.width * data.height;
density = 0;
@ -140,9 +140,9 @@ function getPrediction() {
density = density*1.0 / size;
tmp_tableau.push(density);
curHeight += stepSize;
curWidth += stepSize;
}
curWidth += stepSize;
curHeight += stepSize;
tableau.push(tmp_tableau);
}