Update neuron_io

This commit is contained in:
augustin64 2022-05-21 15:11:36 +02:00
parent 45c39d8880
commit 986707af2b
2 changed files with 10 additions and 9 deletions

View File

@ -11,8 +11,15 @@
Neuron* read_neuron(uint32_t nb_weights, FILE *ptr); Neuron* read_neuron(uint32_t nb_weights, FILE *ptr);
Neuron** read_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr); Neuron** read_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr);
Network* read_network(char* filename); Network* read_network(char* filename);
void ecrire_neuron(Neuron* neuron, int weights, FILE *ptr);
void write_neuron(Neuron* neuron, int weights, FILE *ptr);
void write_network(char* filename, Network* network); void write_network(char* filename, Network* network);
Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr);
Neuron** read_delta_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr);
Network* read_delta_network(char* filename);
void write_delta_neuron(Neuron* neuron, int weights, FILE *ptr);
void write_delta_network(char* filename, Network* network); void write_delta_network(char* filename, Network* network);
#endif #endif

View File

@ -27,11 +27,9 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
neuron->last_back_bias = 0.0; neuron->last_back_bias = 0.0;
neuron->back_bias = 0.0; neuron->back_bias = 0.0;
float* weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights); neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights); neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->weights = weights; neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
for (int i=0; i < (int)nb_weights; i++) { for (int i=0; i < (int)nb_weights; i++) {
fread(&tmp, sizeof(float), 1, ptr); fread(&tmp, sizeof(float), 1, ptr);
@ -40,7 +38,6 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
neuron->last_back_weights[i] = 0.0; neuron->last_back_weights[i] = 0.0;
} }
free(weights);
return neuron; return neuron;
} }
@ -160,11 +157,9 @@ Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr) {
neuron->last_back_bias = 0.0; neuron->last_back_bias = 0.0;
neuron->back_bias = back_bias; neuron->back_bias = back_bias;
float* back_weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights); neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights); neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->weights = back_weights; neuron->weights = (float*)malloc(sizeof(float)*nb_weights);
for (int i=0; i < (int)nb_weights; i++) { for (int i=0; i < (int)nb_weights; i++) {
fread(&tmp, sizeof(float), 1, ptr); fread(&tmp, sizeof(float), 1, ptr);
@ -172,7 +167,6 @@ Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr) {
neuron->back_weights[i] = tmp; neuron->back_weights[i] = tmp;
neuron->last_back_weights[i] = 0.0; neuron->last_back_weights[i] = 0.0;
} }
free(back_weights);
return neuron; return neuron;
} }