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 <stdlib.h>
#include "../include/memory_management.h"
#include "include/initialisation.h"
#include "include/function.h"
#include "../include/utils.h"

View File

@ -1,7 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include "../include/utils.h"
#include "../include/memory_management.h"
#include "include/free.h"
@ -103,8 +103,9 @@ void free_dense_linearisation(Network* network, int pos) {
void free_network_creation(Network* network) {
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->width);
gree(network->depth);
gree(network->kernel);

View File

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

View File

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

View File

@ -38,11 +38,11 @@ void preview_images(char* path, int limit) {
if (!dataset->images[i]) {
image = loadJpegImageFile(dataset->fileNames[i]);
dataset->images[i] = image->lpData;
gree(image);
free(image);
}
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 <string.h>
#include "../include/memory_management.h"
#include "../mnist/include/mnist.h"
#include "include/neuron_io.h"
#include "../include/utils.h"
#include "include/struct.h"
#include "include/jpeg.h"
#include "include/free.h"

View File

@ -7,6 +7,7 @@
#include <time.h>
#include <omp.h>
#include "../include/memory_management.h"
#include "../mnist/include/mnist.h"
#include "include/initialisation.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
int* parameters = read_mnist_images_parameters(images_file);
nb_images_total = parameters[0];
gree(parameters);
free(parameters);
images = read_mnist_images(images_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é.
// 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.
TrainParameters* train_params = (TrainParameters*)nalloc(sizeof(TrainParameters));
TrainParameters* train_params = (TrainParameters*)malloc(sizeof(TrainParameters));
train_params->network = network;
train_params->dataset_type = dataset_type;

View File

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

View File

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