Change headers

This commit is contained in:
augustin64 2023-02-18 13:10:00 +01:00
parent 795d8b68d7
commit 5c7c013d91
9 changed files with 31 additions and 26 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../include/memory_management.h"
#include "include/initialisation.h" #include "include/initialisation.h"
#include "include/function.h" #include "include/function.h"
#include "../include/utils.h" #include "../include/utils.h"

View File

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "../include/utils.h" #include "../include/memory_management.h"
#include "include/free.h" #include "include/free.h"
@ -103,8 +103,9 @@ void free_dense_linearisation(Network* network, int pos) {
void free_network_creation(Network* network) { void free_network_creation(Network* network) {
free_a_cube_input_layer(network, 0, network->depth[0], network->width[0]); free_a_cube_input_layer(network, 0, network->depth[0], network->width[0]);
for (int i=0; i < network->max_size-1; i++) for (int i=0; i < network->max_size-1; i++) {
gree(network->kernel[i]); gree(network->kernel[i]);
}
gree(network->width); gree(network->width);
gree(network->depth); gree(network->depth);
gree(network->kernel); gree(network->kernel);

View File

@ -53,9 +53,9 @@ imgRawImage* loadJpegImageFile(char* lpFilename) {
#endif #endif
dwBufferBytes = imgWidth * imgHeight * 3; /* We only read RGB, not A */ dwBufferBytes = imgWidth * imgHeight * 3; /* We only read RGB, not A */
lpData = (unsigned char*)nalloc(sizeof(unsigned char)*dwBufferBytes); lpData = (unsigned char*)malloc(sizeof(unsigned char)*dwBufferBytes);
lpNewImage = (imgRawImage*)nalloc(sizeof(imgRawImage)); lpNewImage = (imgRawImage*)malloc(sizeof(imgRawImage));
lpNewImage->numComponents = numComponents; lpNewImage->numComponents = numComponents;
lpNewImage->width = imgWidth; lpNewImage->width = imgWidth;
lpNewImage->height = imgHeight; lpNewImage->height = imgHeight;
@ -75,7 +75,7 @@ imgRawImage* loadJpegImageFile(char* lpFilename) {
} }
jpegDataset* loadJpegDataset(char* folderPath) { jpegDataset* loadJpegDataset(char* folderPath) {
jpegDataset* dataset = (jpegDataset*)nalloc(sizeof(jpegDataset)); jpegDataset* dataset = (jpegDataset*)malloc(sizeof(jpegDataset));
imgRawImage* image; imgRawImage* image;
// We start by counting the number of images and categories // We start by counting the number of images and categories
@ -83,8 +83,8 @@ jpegDataset* loadJpegDataset(char* folderPath) {
dataset->numImages = countFiles(folderPath); dataset->numImages = countFiles(folderPath);
dataset->images = NULL; dataset->images = NULL;
dataset->labels = (unsigned int*)nalloc(sizeof(unsigned int)*dataset->numImages); dataset->labels = (unsigned int*)malloc(sizeof(unsigned int)*dataset->numImages);
dataset->fileNames = (char**)nalloc(sizeof(char*)*dataset->numImages); dataset->fileNames = (char**)malloc(sizeof(char*)*dataset->numImages);
DIR* dirp; DIR* dirp;
struct dirent* entry; struct dirent* entry;
@ -97,17 +97,17 @@ jpegDataset* loadJpegDataset(char* folderPath) {
if (strcmp(entry->d_name, ".")&&strcmp(entry->d_name, "..")) { if (strcmp(entry->d_name, ".")&&strcmp(entry->d_name, "..")) {
if (entry->d_type == DT_DIR) { if (entry->d_type == DT_DIR) {
prev_index = index; prev_index = index;
concatenated_path = nalloc(strlen(folderPath)+strlen(entry->d_name)+2); concatenated_path = malloc(strlen(folderPath)+strlen(entry->d_name)+2);
sprintf(concatenated_path, "%s/%s", folderPath, entry->d_name); sprintf(concatenated_path, "%s/%s", folderPath, entry->d_name);
addFilenamesToArray(concatenated_path, dataset->fileNames, &index); addFilenamesToArray(concatenated_path, dataset->fileNames, &index);
for (int i=prev_index; i < index; i++) { for (int i=prev_index; i < index; i++) {
dataset->labels[i] = getLabel(entry->d_name); dataset->labels[i] = getLabel(entry->d_name);
} }
gree(concatenated_path); free(concatenated_path);
} }
} }
} }
dataset->images = (unsigned char**)nalloc(sizeof(unsigned char*)*dataset->numImages); dataset->images = (unsigned char**)malloc(sizeof(unsigned char*)*dataset->numImages);
for (int i=0; i < (int)dataset->numImages; i++) { for (int i=0; i < (int)dataset->numImages; i++) {
dataset->images[i] = NULL; dataset->images[i] = NULL;
#ifdef STORE_IMAGES_TO_RAM #ifdef STORE_IMAGES_TO_RAM
@ -117,7 +117,7 @@ jpegDataset* loadJpegDataset(char* folderPath) {
} }
image = loadJpegImageFile(dataset->fileNames[i]); image = loadJpegImageFile(dataset->fileNames[i]);
dataset->images[i] = image->lpData; dataset->images[i] = image->lpData;
gree(image); free(image);
#endif #endif
} }
#ifdef STORE_IMAGES_TO_RAM #ifdef STORE_IMAGES_TO_RAM
@ -130,8 +130,8 @@ jpegDataset* loadJpegDataset(char* folderPath) {
dataset->height = image->height; dataset->height = image->height;
dataset->numComponents = image->numComponents; dataset->numComponents = image->numComponents;
gree(image->lpData); free(image->lpData);
gree(image); free(image);
closedir(dirp); closedir(dirp);
return dataset; return dataset;
@ -185,7 +185,7 @@ void addFilenamesToArray(char* path, char** array, int* index) {
dirp = opendir(path); /* There should be error handling after this */ dirp = opendir(path); /* There should be error handling after this */
while ((entry = readdir(dirp)) != NULL) { while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_REG) { /* If the entry is a regular file */ if (entry->d_type == DT_REG) { /* If the entry is a regular file */
filename = (char*)nalloc(strlen(path)+strlen(entry->d_name)+2); filename = (char*)malloc(strlen(path)+strlen(entry->d_name)+2);
sprintf(filename, "%s/%s", path, entry->d_name); sprintf(filename, "%s/%s", path, entry->d_name);
array[i] = filename; array[i] = filename;
i++; i++;
@ -197,15 +197,15 @@ void addFilenamesToArray(char* path, char** array, int* index) {
void free_dataset(jpegDataset* dataset) { void free_dataset(jpegDataset* dataset) {
for (int i=0; i < (int)dataset->numImages; i++) { for (int i=0; i < (int)dataset->numImages; i++) {
gree(dataset->fileNames[i]); free(dataset->fileNames[i]);
#ifdef STORE_IMAGES_TO_RAM #ifdef STORE_IMAGES_TO_RAM
gree(dataset->images[i]); free(dataset->images[i]);
#endif #endif
} }
gree(dataset->fileNames); free(dataset->fileNames);
gree(dataset->labels); free(dataset->labels);
gree(dataset->images); free(dataset->images);
gree(dataset); free(dataset);
} }
unsigned int getLabel(char* string) { unsigned int getLabel(char* string) {

View File

@ -3,8 +3,8 @@
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include "../include/memory_management.h"
#include "../include/colors.h" #include "../include/colors.h"
#include "../include/utils.h"
#include "include/function.h" #include "include/function.h"
#include "include/struct.h" #include "include/struct.h"

View File

@ -38,11 +38,11 @@ void preview_images(char* path, int limit) {
if (!dataset->images[i]) { if (!dataset->images[i]) {
image = loadJpegImageFile(dataset->fileNames[i]); image = loadJpegImageFile(dataset->fileNames[i]);
dataset->images[i] = image->lpData; dataset->images[i] = image->lpData;
gree(image); free(image);
} }
print_image(dataset->images[i], dataset->height, dataset->width); print_image(dataset->images[i], dataset->height, dataset->width);
gree(dataset->images[i]); free(dataset->images[i]);
} }
} }

View File

@ -3,9 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include "../include/memory_management.h"
#include "../mnist/include/mnist.h" #include "../mnist/include/mnist.h"
#include "include/neuron_io.h" #include "include/neuron_io.h"
#include "../include/utils.h"
#include "include/struct.h" #include "include/struct.h"
#include "include/jpeg.h" #include "include/jpeg.h"
#include "include/free.h" #include "include/free.h"

View File

@ -7,6 +7,7 @@
#include <time.h> #include <time.h>
#include <omp.h> #include <omp.h>
#include "../include/memory_management.h"
#include "../mnist/include/mnist.h" #include "../mnist/include/mnist.h"
#include "include/initialisation.h" #include "include/initialisation.h"
#include "include/neuron_io.h" #include "include/neuron_io.h"
@ -131,7 +132,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
// Chargement des images du set de données MNIST // Chargement des images du set de données MNIST
int* parameters = read_mnist_images_parameters(images_file); int* parameters = read_mnist_images_parameters(images_file);
nb_images_total = parameters[0]; nb_images_total = parameters[0];
gree(parameters); free(parameters);
images = read_mnist_images(images_file); images = read_mnist_images(images_file);
labels = read_mnist_labels(labels_file); labels = read_mnist_labels(labels_file);
@ -199,7 +200,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
// thread dans l'hypothèse ou le multi-threading n'est pas utilisé. // thread dans l'hypothèse ou le multi-threading n'est pas utilisé.
// Cela est utile à des fins de débogage notamment, // Cela est utile à des fins de débogage notamment,
// où l'utilisation de threads rend vite les choses plus compliquées qu'elles ne le sont. // où l'utilisation de threads rend vite les choses plus compliquées qu'elles ne le sont.
TrainParameters* train_params = (TrainParameters*)nalloc(sizeof(TrainParameters)); TrainParameters* train_params = (TrainParameters*)malloc(sizeof(TrainParameters));
train_params->network = network; train_params->network = network;
train_params->dataset_type = dataset_type; train_params->dataset_type = dataset_type;

View File

@ -6,6 +6,7 @@
#include <time.h> #include <time.h>
#include <omp.h> #include <omp.h>
#include "../src/include/memory_management.h"
#include "../src/cnn/include/convolution.h" #include "../src/cnn/include/convolution.h"
#include "../src/cnn/include/struct.h" #include "../src/cnn/include/struct.h"
#include "../src/include/colors.h" #include "../src/include/colors.h"

View File

@ -6,6 +6,7 @@
#include <omp.h> #include <omp.h>
#include "../src/cnn/include/matrix_multiplication.h" #include "../src/cnn/include/matrix_multiplication.h"
#include "../src/include/memory_management.h"
#include "../src/include/colors.h" #include "../src/include/colors.h"
#include "../src/include/utils.h" #include "../src/include/utils.h"