Darknet/YOLO v5.0-117-g31c55275-dirty
Object Detection Framework
 
Loading...
Searching...
No Matches
utils.cpp File Reference
Include dependency graph for utils.cpp:

Macros

#define _CRT_RAND_S
 
#define MAX_STACK_FRAMES   50
 

Functions

int alphanum_to_int (char c)
 
const char * basecfg (const char *cfgfile)
 
void calloc_error (const size_t size, const char *const filename, const char *const funcname, const int line)
 
float constrain (float min, float max, float a)
 
char * copy_string (char *s)
 
unsigned long custom_hash (const std::string &str)
 
void darknet_fatal_error (const char *const filename, const char *const funcname, const int line, const char *const msg,...)
 Calling this function ends the application. This function will never return control back to the caller.
 
void del_arg (int argc, char **argv, int index)
 
float dist_array (float *a, float *b, int n, int sub)
 
char * fgetl (FILE *fp)
 
void file_error (const char *const s, const char *const filename, const char *const funcname, const int line)
 
int find_arg (int argc, char *argv[], const char *const arg)
 
const char * find_char_arg (int argc, char **argv, const char *arg, const char *def)
 
float find_float_arg (int argc, char **argv, const char *const arg, float def)
 
int find_int_arg (int argc, char **argv, const char *const arg, int def)
 
void find_replace (const char *str, char *orig, char *rep, char *output)
 
void free_ptrs (void **ptrs, int n)
 This is part of the original C API.
 
int int_index (int *a, int val, int n)
 
char int_to_alphanum (int i)
 
void log_backtrace ()
 
float mag_array (float *a, int n)
 
int make_directory (char *path, int mode)
 
void malloc_error (const size_t size, const char *const filename, const char *const funcname, const int line)
 
int max_index (float *a, int n)
 
float mean_array (float *a, int n)
 
void mean_arrays (float **a, int n, int els, float *avg)
 
float mse_array (float *a, int n)
 
void normalize_array (float *a, int n)
 
void print_statistics (float *a, int n)
 
int rand_int (int min, int max)
 The "min" and "max" values are inclusive. For example, rand_int(1, 6) can return 6 possible values.
 
float rand_precalc_random (float min, float max, float random_part)
 
float rand_scale (float s)
 
unsigned int rand_uint (unsigned int min, unsigned int max)
 The "min" and "max" values are inclusive. For example, rand_uint(1, 6) can return 6 possible values.
 
float rand_uniform (float min, float max)
 In V5 this was modified to use std::uniform_real_distribution to return proper C++ pseudo random float values.
 
void rand_uniform_many (float *x, const size_t n, float min, float max, const float scale)
 Somewhat similar to rand_uniform(), but will initialize many values at once instead of having to repeatedly call rand_uniform().
 
void read_all (int fd, char *buffer, size_t bytes)
 
int read_all_fail (int fd, char *buffer, size_t bytes)
 
int read_int (int fd)
 
int * read_map (const char *filename)
 
void realloc_error (const size_t size, const char *const filename, const char *const funcname, const int line)
 
void replace_image_to_label (const char *input_path, char *output_path)
 
void scale_array (float *a, int n, float s)
 
float sec (clock_t clocks)
 
void shuffle (void *arr, size_t n, size_t size)
 
std::string size_to_IEC_string (const size_t size)
 Convert the given size to a human-readable string. This uses 1024 as a divider, so 1 KiB == 1024 bytes.
 
void sorta_shuffle (void *arr, size_t n, size_t size, size_t sections)
 
listsplit_str (char *s, char delim)
 
void strip (char *s)
 
void strip_args (char *s)
 
void strip_char (char *s, char bad)
 
float sum_array (float *a, int n)
 
void top_k (float *a, int n, int k, int *index)
 
int top_max_index (float *a, int n, int k)
 
void translate_array (float *a, int n, float s)
 
float variance_array (float *a, int n)
 
void write_all (int fd, char *buffer, size_t bytes)
 
int write_all_fail (int fd, char *buffer, size_t bytes)
 
void write_int (int fd, int n)
 
void * xcalloc_location (const size_t nmemb, const size_t size, const char *const filename, const char *const funcname, const int line)
 
void * xmalloc_location (const size_t size, const char *const filename, const char *const funcname, const int line)
 
void * xrealloc_location (void *ptr, const size_t size, const char *const filename, const char *const funcname, const int line)
 

Macro Definition Documentation

◆ _CRT_RAND_S

#define _CRT_RAND_S

◆ MAX_STACK_FRAMES

#define MAX_STACK_FRAMES   50

Function Documentation

◆ alphanum_to_int()

int alphanum_to_int ( char  c)

◆ basecfg()

const char * basecfg ( const char *  cfgfile)
Todo:
2025-04-18 replace all of this with std::filesystem::path::stem()?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calloc_error()

void calloc_error ( const size_t  size,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ constrain()

float constrain ( float  min,
float  max,
float  a 
)
Here is the caller graph for this function:

◆ copy_string()

char * copy_string ( char *  s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ custom_hash()

unsigned long custom_hash ( const std::string &  str)
Here is the caller graph for this function:

◆ darknet_fatal_error()

void darknet_fatal_error ( const char *const  filename,
const char *const  funcname,
const int  line,
const char *const  msg,
  ... 
)

Calling this function ends the application. This function will never return control back to the caller.

See also
DARKNET_LOC
Here is the call graph for this function:

◆ del_arg()

void del_arg ( int  argc,
char **  argv,
int  index 
)
Here is the caller graph for this function:

◆ dist_array()

float dist_array ( float *  a,
float *  b,
int  n,
int  sub 
)
Here is the caller graph for this function:

◆ fgetl()

char * fgetl ( FILE *  fp)
Here is the caller graph for this function:

◆ file_error()

void file_error ( const char *const  s,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_arg()

int find_arg ( int  argc,
char *  argv[],
const char *const  arg 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_char_arg()

const char * find_char_arg ( int  argc,
char **  argv,
const char *  arg,
const char *  def 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_float_arg()

float find_float_arg ( int  argc,
char **  argv,
const char *const  arg,
float  def 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_int_arg()

int find_int_arg ( int  argc,
char **  argv,
const char *const  arg,
int  def 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_replace()

void find_replace ( const char *  str,
char *  orig,
char *  rep,
char *  output 
)

◆ free_ptrs()

void free_ptrs ( void **  ptrs,
int  n 
)

This is part of the original C API.

Here is the caller graph for this function:

◆ int_index()

int int_index ( int *  a,
int  val,
int  n 
)
Here is the caller graph for this function:

◆ int_to_alphanum()

char int_to_alphanum ( int  i)

◆ log_backtrace()

void log_backtrace ( )
Here is the caller graph for this function:

◆ mag_array()

float mag_array ( float *  a,
int  n 
)
Here is the caller graph for this function:

◆ make_directory()

int make_directory ( char *  path,
int  mode 
)
Here is the caller graph for this function:

◆ malloc_error()

void malloc_error ( const size_t  size,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ max_index()

int max_index ( float *  a,
int  n 
)
Here is the caller graph for this function:

◆ mean_array()

float mean_array ( float *  a,
int  n 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mean_arrays()

void mean_arrays ( float **  a,
int  n,
int  els,
float *  avg 
)

◆ mse_array()

float mse_array ( float *  a,
int  n 
)
Here is the caller graph for this function:

◆ normalize_array()

void normalize_array ( float *  a,
int  n 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_statistics()

void print_statistics ( float *  a,
int  n 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rand_int()

int rand_int ( int  min,
int  max 
)

The "min" and "max" values are inclusive. For example, rand_int(1, 6) can return 6 possible values.

Here is the caller graph for this function:

◆ rand_precalc_random()

float rand_precalc_random ( float  min,
float  max,
float  random_part 
)
Here is the caller graph for this function:

◆ rand_scale()

float rand_scale ( float  s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rand_uint()

unsigned int rand_uint ( unsigned int  min,
unsigned int  max 
)

The "min" and "max" values are inclusive. For example, rand_uint(1, 6) can return 6 possible values.

Here is the caller graph for this function:

◆ rand_uniform()

float rand_uniform ( float  min,
float  max 
)

In V5 this was modified to use std::uniform_real_distribution to return proper C++ pseudo random float values.

The "min" is inclusive, and "max" is exclusive, so rand_uniform(0.0f, 5.0f) will return 0.0f but never 5.0f. The "min" and "max" values will automatically be swapped if necessary. This will never return NaN or infinite values.

Here is the caller graph for this function:

◆ rand_uniform_many()

void rand_uniform_many ( float *  x,
const size_t  n,
float  min,
float  max,
const float  scale = 1.0f 
)

Somewhat similar to rand_uniform(), but will initialize many values at once instead of having to repeatedly call rand_uniform().

Especially useful when initializing a large number of weights on startup.

Since
2025-07-16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_all()

void read_all ( int  fd,
char *  buffer,
size_t  bytes 
)
Here is the call graph for this function:

◆ read_all_fail()

int read_all_fail ( int  fd,
char *  buffer,
size_t  bytes 
)

◆ read_int()

int read_int ( int  fd)

◆ read_map()

int * read_map ( const char *  filename)
Todo:
what is this "map" file that we're reading in?
Todo:
the while loop reallocs the array at every iteration, this needs to be refactored!
Here is the call graph for this function:
Here is the caller graph for this function:

◆ realloc_error()

void realloc_error ( const size_t  size,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_image_to_label()

void replace_image_to_label ( const char *  input_path,
char *  output_path 
)
Here is the caller graph for this function:

◆ scale_array()

void scale_array ( float *  a,
int  n,
float  s 
)

◆ sec()

float sec ( clock_t  clocks)

◆ shuffle()

void shuffle ( void *  arr,
size_t  n,
size_t  size 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size_to_IEC_string()

std::string size_to_IEC_string ( const size_t  size)

Convert the given size to a human-readable string. This uses 1024 as a divider, so 1 KiB == 1024 bytes.

Here is the caller graph for this function:

◆ sorta_shuffle()

void sorta_shuffle ( void *  arr,
size_t  n,
size_t  size,
size_t  sections 
)
Here is the call graph for this function:

◆ split_str()

list * split_str ( char *  s,
char  delim 
)
Here is the call graph for this function:

◆ strip()

void strip ( char *  s)
Here is the caller graph for this function:

◆ strip_args()

void strip_args ( char *  s)

◆ strip_char()

void strip_char ( char *  s,
char  bad 
)

◆ sum_array()

float sum_array ( float *  a,
int  n 
)
Here is the caller graph for this function:

◆ top_k()

void top_k ( float *  a,
int  n,
int  k,
int *  index 
)
Here is the caller graph for this function:

◆ top_max_index()

int top_max_index ( float *  a,
int  n,
int  k 
)
Here is the call graph for this function:

◆ translate_array()

void translate_array ( float *  a,
int  n,
float  s 
)

◆ variance_array()

float variance_array ( float *  a,
int  n 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_all()

void write_all ( int  fd,
char *  buffer,
size_t  bytes 
)
Here is the call graph for this function:

◆ write_all_fail()

int write_all_fail ( int  fd,
char *  buffer,
size_t  bytes 
)

◆ write_int()

void write_int ( int  fd,
int  n 
)
Here is the call graph for this function:

◆ xcalloc_location()

void * xcalloc_location ( const size_t  nmemb,
const size_t  size,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function:

◆ xmalloc_location()

void * xmalloc_location ( const size_t  size,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function:

◆ xrealloc_location()

void * xrealloc_location ( void *  ptr,
const size_t  size,
const char *const  filename,
const char *const  funcname,
const int  line 
)
Here is the call graph for this function: