mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-24 07:36:24 +01:00
Add casts
This commit is contained in:
parent
ce947fe91d
commit
13c59de4ec
@ -19,9 +19,9 @@ int** read_image(unsigned int width, unsigned int height, FILE* ptr) {
|
|||||||
|
|
||||||
fread(buffer, sizeof(buffer), 1, ptr);
|
fread(buffer, sizeof(buffer), 1, ptr);
|
||||||
|
|
||||||
for (int i=0; i<height; i++) {
|
for (int i=0; i < (int)height; i++) {
|
||||||
int* line = (int*)malloc(line_size);
|
int* line = (int*)malloc(line_size);
|
||||||
for (int j=0; j<width; j++) {
|
for (int j=0; j < (int)width; j++) {
|
||||||
line[j] = (int)buffer[j+i*width];
|
line[j] = (int)buffer[j+i*width];
|
||||||
}
|
}
|
||||||
image[i] = line;
|
image[i] = line;
|
||||||
@ -31,7 +31,7 @@ int** read_image(unsigned int width, unsigned int height, FILE* ptr) {
|
|||||||
|
|
||||||
// renvoie [nb_elem, width, height]
|
// renvoie [nb_elem, width, height]
|
||||||
int* read_mnist_images_parameters(char* filename) {
|
int* read_mnist_images_parameters(char* filename) {
|
||||||
int* tab = malloc(sizeof(int)*3);
|
int* tab = (int*)malloc(sizeof(int)*3);
|
||||||
FILE *ptr;
|
FILE *ptr;
|
||||||
|
|
||||||
ptr = fopen(filename, "rb");
|
ptr = fopen(filename, "rb");
|
||||||
@ -113,7 +113,7 @@ int*** read_mnist_images(char* filename) {
|
|||||||
|
|
||||||
int*** tab = (int***)malloc(sizeof(int**)*number_of_images);
|
int*** tab = (int***)malloc(sizeof(int**)*number_of_images);
|
||||||
|
|
||||||
for (int i=0; i < number_of_images; i++) {
|
for (int i=0; i < (int)number_of_images; i++) {
|
||||||
tab[i] = read_image(width, height, ptr);
|
tab[i] = read_image(width, height, ptr);
|
||||||
}
|
}
|
||||||
return tab;
|
return tab;
|
||||||
@ -142,9 +142,9 @@ unsigned int* read_mnist_labels(char* filename) {
|
|||||||
unsigned char buffer[number_of_items];
|
unsigned char buffer[number_of_items];
|
||||||
fread(buffer, sizeof(unsigned char), number_of_items, ptr);
|
fread(buffer, sizeof(unsigned char), number_of_items, ptr);
|
||||||
|
|
||||||
unsigned int* labels = malloc(sizeof(unsigned int)*number_of_items);
|
unsigned int* labels = (unsigned int*)malloc(sizeof(unsigned int)*number_of_items);
|
||||||
|
|
||||||
for (int i=0; i< number_of_items; i++) {
|
for (int i=0; i < (int)number_of_items; i++) {
|
||||||
labels[i] = (unsigned int)buffer[i];
|
labels[i] = (unsigned int)buffer[i];
|
||||||
}
|
}
|
||||||
return labels;
|
return labels;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
|
|
||||||
Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
||||||
Neuron* neuron = malloc(sizeof(Neuron));
|
Neuron* neuron = (Neuron*)malloc(sizeof(Neuron));
|
||||||
float activation;
|
float activation;
|
||||||
float bias;
|
float bias;
|
||||||
float tmp;
|
float tmp;
|
||||||
@ -23,13 +23,13 @@ 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 = malloc(sizeof(float)*nb_weights);
|
float* weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||||
|
|
||||||
neuron->last_back_weights = malloc(sizeof(float)*nb_weights);
|
neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||||
neuron->back_weights = malloc(sizeof(float)*nb_weights);
|
neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights);
|
||||||
neuron->weights = weights;
|
neuron->weights = weights;
|
||||||
|
|
||||||
for (int i=0; i < nb_weights; i++) {
|
for (int i=0; i < (int)nb_weights; i++) {
|
||||||
fread(&tmp, sizeof(float), 1, ptr);
|
fread(&tmp, sizeof(float), 1, ptr);
|
||||||
neuron->weights[i] = tmp;
|
neuron->weights[i] = tmp;
|
||||||
neuron->back_weights[i] = 0.0;
|
neuron->back_weights[i] = 0.0;
|
||||||
@ -42,8 +42,8 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
|
|||||||
|
|
||||||
// Lit une couche de neurones
|
// Lit une couche de neurones
|
||||||
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) {
|
||||||
Neuron** neurons = malloc(sizeof(Neuron*)*nb_neurons);
|
Neuron** neurons = (Neuron**)malloc(sizeof(Neuron*)*nb_neurons);
|
||||||
for (int i=0; i < nb_neurons; i++) {
|
for (int i=0; i < (int)nb_neurons; i++) {
|
||||||
neurons[i] = read_neuron(nb_weights, ptr);
|
neurons[i] = read_neuron(nb_weights, ptr);
|
||||||
}
|
}
|
||||||
return neurons;
|
return neurons;
|
||||||
@ -53,7 +53,7 @@ Neuron** read_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr) {
|
|||||||
// Charge l'entièreté du réseau neuronal depuis un fichier binaire
|
// Charge l'entièreté du réseau neuronal depuis un fichier binaire
|
||||||
Network* read_network(char* filename) {
|
Network* read_network(char* filename) {
|
||||||
FILE *ptr;
|
FILE *ptr;
|
||||||
Network* network = malloc(sizeof(Network));
|
Network* network = (Network*)malloc(sizeof(Network));
|
||||||
|
|
||||||
ptr = fopen(filename, "rb");
|
ptr = fopen(filename, "rb");
|
||||||
|
|
||||||
@ -71,20 +71,20 @@ Network* read_network(char* filename) {
|
|||||||
network->nb_layers = nb_layers;
|
network->nb_layers = nb_layers;
|
||||||
|
|
||||||
|
|
||||||
Layer** layers = malloc(sizeof(Layer*)*nb_layers);
|
Layer** layers = (Layer**)malloc(sizeof(Layer*)*nb_layers);
|
||||||
uint32_t nb_neurons_layer[nb_layers+1];
|
uint32_t nb_neurons_layer[nb_layers+1];
|
||||||
|
|
||||||
network->layers = layers;
|
network->layers = layers;
|
||||||
|
|
||||||
for (int i=0; i < nb_layers; i++) {
|
for (int i=0; i < (int)nb_layers; i++) {
|
||||||
layers[i] = malloc(sizeof(Layer));
|
layers[i] = (Layer*)malloc(sizeof(Layer));
|
||||||
fread(&tmp, sizeof(tmp), 1, ptr);
|
fread(&tmp, sizeof(tmp), 1, ptr);
|
||||||
layers[i]->nb_neurons = tmp;
|
layers[i]->nb_neurons = tmp;
|
||||||
nb_neurons_layer[i] = tmp;
|
nb_neurons_layer[i] = tmp;
|
||||||
}
|
}
|
||||||
nb_neurons_layer[nb_layers] = 0;
|
nb_neurons_layer[nb_layers] = 0;
|
||||||
|
|
||||||
for (int i=0; i < nb_layers; i++) {
|
for (int i=0; i < (int)nb_layers; i++) {
|
||||||
layers[i]->neurons = read_neurons(layers[i]->nb_neurons, nb_neurons_layer[i+1], ptr);
|
layers[i]->neurons = read_neurons(layers[i]->nb_neurons, nb_neurons_layer[i+1], ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user