OCR Project
Loading...
Searching...
No Matches
model.c File Reference

Binary save/load of CNN weights and latest-model discovery. More...

#include "model.h"
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
Include dependency graph for model.c:

Functions

int model_save (const CNN *net, const char *path)
 Save the weights of a trained CNN to a binary file.
int model_load (CNN *net, const char *path)
 Load CNN weights from a binary file into net.
int model_find_latest (const char *dir, char *out_path, size_t out_len)
 Find the most recently modified .bin file inside a directory.

Detailed Description

Binary save/load of CNN weights and latest-model discovery.

Function Documentation

◆ model_find_latest()

int model_find_latest ( const char * dir,
char * out_path,
size_t out_len )

Find the most recently modified .bin file inside a directory.

Iterates over all regular files with a ".bin" suffix in dir and returns the one with the highest mtime.

Parameters
dirDirectory to search (e.g. "models/").
out_pathBuffer that receives the full path of the chosen file.
out_lenSize of out_path in bytes.
Returns
0 if a file was found and written to out_path, -1 if the directory is empty or cannot be opened.
Here is the caller graph for this function:

◆ model_load()

int model_load ( CNN * net,
const char * path )

Load CNN weights from a binary file into net.

Validates the magic number and version before reading. If validation fails, net is left unchanged.

Parameters
netCNN to load weights into. Must not be NULL.
pathSource file path.
Returns
0 on success, -1 on I/O error or format mismatch.
Here is the caller graph for this function:

◆ model_save()

int model_save ( const CNN * net,
const char * path )

Save the weights of a trained CNN to a binary file.

Creates or overwrites the file at path. The directory must exist.

Parameters
netCNN whose weights should be saved. Must not be NULL.
pathDestination file path (e.g. "models/my_model.bin").
Returns
0 on success, -1 on I/O error (message printed to stderr).
Here is the caller graph for this function: