SqueezeBrains SDK 1.13
Generic

Generic functions. More...

Collaboration diagram for Generic:

Data Structures

struct  sb_t_version
 Defines the version. More...
 
struct  sb_t_memory_info
 Memory information. More...
 
struct  sb_t_device_info
 Information about a computing device. More...
 
struct  sb_t_devices_info
 List of computing devices available on the machine. More...
 
struct  sb_t_info
 General information about sb library and computing devices like CPU and GPUs. More...
 
struct  sb_t_bgra
 Defines the color in the format BGRA. More...
 
struct  sb_t_rgba
 Defines the color in the format RGBA. More...
 

Macros

#define SB_INIT_ONLY_HW_LICENSE_KEY   "ONLY_HW_KEY"
 Use this define with sb_init in order to manage only hardware license keys. More...
 
#define SB_INIT_ONLY_SB_LICENSE_KEY   "ONLY_SB_KEY"
 Use this define with sb_init in order to manage only SqueezeBrains software license keys. More...
 
#define SB_INIT_NO_LICENSE_KEY   "NO_KEY"
 Use this define with sb_init in order to not manage license keys. More...
 
#define SB_DELIMITER   ";"
 Use this define as delimiter. More...
 
#define SB_VALUE_NOT_SET   1000000.0f
 Value of the prediction in case it is undefined. More...
 
#define SB_PAR_MODELS_NUM   64
 Maximum number of models.
 
#define SB_PAR_PERTURBATIONS_NUM   16
 Maximum number of perturbation of a sample.
 
#define SB_PAR_STRING_LEN   64
 Maximum length, in byte, of a parameter string.
 
#define SB_IMAGE_NAME_STRING_LEN   128
 Maximum length, in byte, of the image name string.
 
#define SB_PAR_LEVELS_NUM   32
 Maximum scales levels number to be used for Surface.
 
#define SB_PAR_LEVEL_SCALE_GRANULARITY   0.50f
 Scale granularity for multi-scale defects detection.
 
#define SB_PAR_LEVEL_SCALE_MIN   1.0f
 Minimum scale factor of surface.
 
#define SB_PAR_LEVEL_SCALE_MAX   16.0f
 Maximum scale factor of surface.
 
#define SB_PAR_RETINA_OBJ_SIZE_MIN   24
 Minimum value of sb_t_par_model::obj_size.
 
#define SB_PAR_RETINA_OBJ_SIZE_MAX   1024
 Maximum value of sb_t_par_model::obj_size.
 
#define SB_PAR_RETINA_OBJ_STRIDE_COARSE_MIN   4
 Minimum value of sb_t_par_model::obj_stride_coarse.
 
#define SB_PAR_RETINA_OBJ_STRIDE_COARSE_MAX   32
 Maximum value of sb_t_par_model::obj_stride_coarse.
 
#define SB_PAR_RETINA_OBJ_STRIDE_FINE_MIN   1
 Minimum value of sb_t_par_model::obj_stride_fine.
 
#define SB_PAR_RETINA_OBJ_STRIDE_FINE_MAX   8
 Maximum value of sb_t_par_model::obj_stride_fine.
 
#define SB_PAR_RETINA_OBJ_DISTANCE_MIN   4
 Minimum value of sb_t_par_model::obj_min_distance.
 
#define SB_PAR_RETINA_NUM_OCCURRENCES_MIN   -1
 Minimum value of sb_t_par_model::num_occurrences.
 
#define SB_SAMPLE_SCALE_GRANULARITY   0.25f
 Scale granularity for multi-scale objects detection.
 
#define SB_SAMPLE_SCALE_MIN   1.0f
 Minimum scale factor of samples.
 
#define SB_SAMPLE_SCALE_MAX   32.0f
 Maximum scale factor of samples.
 
#define SB_SVL_DL_BATCH_SIZE_MIN   4
 Minimum value of sb_t_svl_dl_par::batch_size parameter.
 
#define SB_SVL_DL_BATCH_SIZE_MAX   512
 Maximum value of sb_t_svl_dl_par::batch_size parameter.
 
#define SB_SVL_DL_VALIDATION_PERCENTAGE_MIN   0.0f
 Minimum value of sb_t_svl_dl_par::validation_percentage parameter.
 
#define SB_SVL_DL_VALIDATION_PERCENTAGE_MAX   0.5f
 Maximum value of sb_t_svl_dl_par::validation_percentage parameter.
 
#define SB_SVL_DL_LEARNING_RATE_MIN   0.000001f
 Minimum value of sb_t_svl_dl_par::learning_rate parameter.
 
#define SB_SVL_DL_LEARNING_RATE_MAX   0.01f
 Maximum value of sb_t_svl_dl_par::learning_rate parameter.
 
#define SB_SVL_DL_LEARNING_RATE_DEFAULT   0.001f
 Default value of sb_t_svl_dl_par::learning_rate parameter.
 
#define SB_SVL_DL_TILE_FACTOR_MIN   1
 Minimum value of sb_t_svl_dl_par::tile_factor parameter.
 
#define SB_SVL_DL_TILE_FACTOR_MAX   64
 Maximum value of sb_t_svl_dl_par::tile_factor parameter.
 
#define SB_SVL_DL_FEATURES_MULTIPLIER_MIN   0.5f
 Minimum value of sb_t_svl_dl_par_network::features_multiplier parameter.
 
#define SB_SVL_DL_FEATURES_MULTIPLIER_MAX   1.5f
 Maximum value of sb_t_svl_dl_par_network::features_multiplier parameter.
 
#define SB_SVL_DL_FEATURES_MULTIPLIER_GRANULARITY   0.1f
 Granularity of sb_t_svl_dl_par_network::features_multiplier parameter.
 
#define SB_SVL_DL_FEATURES_MULTIPLIER_DEFAULT   1.0f
 Default value of sb_t_svl_dl_par_network::features_multiplier parameter.
 
#define SB_SVL_DL_SCALE_MIN   1.0f
 Minimum value of sb_t_svl_dl_par::scale parameter.
 
#define SB_SVL_DL_SCALE_MAX   16.0f
 Maximum value of sb_t_svl_dl_par::scale parameter.
 
#define SB_SVL_DL_SCALE_GRANULARITY   0.01f
 Granularity of the value of sb_t_svl_dl_par::scale parameter.
 
#define SB_SVL_DL_PERTURBATION_SHIFT_MIN   0.0f
 Minimum value of sb_t_svl_dl_par_perturbation::shift_horizontal and sb_t_svl_dl_par_perturbation.shift_vertical parameters.
 
#define SB_SVL_DL_PERTURBATION_SHIFT_MAX   0.5f
 Maximum value of sb_t_svl_dl_par_perturbation::shift_horizontal and sb_t_svl_dl_par_perturbation.shift_vertical parameters.
 
#define SB_SVL_DL_PERTURBATION_STRETCH_CONTRAST_MIN   0.0f
 Minimum value of sb_t_svl_dl_par_perturbation::stretch_contrast parameter.
 
#define SB_SVL_DL_PERTURBATION_STRETCH_CONTRAST_MAX   0.5f
 Maximum value of sb_t_svl_dl_par_perturbation::stretch_contrast parameter.
 
#define SB_SVL_DL_PERTURBATION_DELTA_BRIGHTNESS_MIN   0.0f
 Minimum value of sb_t_svl_dl_par_perturbation::delta_brightness parameter.
 
#define SB_SVL_DL_PERTURBATION_DELTA_BRIGHTNESS_MAX   0.5f
 Maximum value of sb_t_svl_dl_par_perturbation::delta_brightness parameter.
 
#define SB_SURFACE_OPTIONAL_GRAY_LEVEL   128
 Gray level for "all model" optional defects. More...
 

Typedefs

typedef void * SB_HANDLE
 HANDLE definition.
 

Enumerations

enum  sb_t_device_type { SB_DEVICE_CPU = 0 , SB_DEVICE_GPU }
 Defines computing device types. More...
 
enum  sb_t_interpolation_mode { SB_INTERPOLATION_MODE_BILINEAR = 0 , SB_INTERPOLATION_MODE_NN }
 Enumerates the interpolation modes. More...
 
enum  sb_t_floating_point_op_type { SB_FLOATING_POINT_OPS_TYPE_SINGLE_PRECISION = 0 , SB_FLOATING_POINT_OPS_TYPE_HALF_PRECISION }
 Enumerates the floating point precision types to perform operations. More...
 

Functions

sb_t_err sb_init (const char *const license_file)
 Initializes the SB library. More...
 
sb_t_err sb_init_dl (const char *const search_path)
 Initialize the Deep Learning library. More...
 
sb_t_err sb_release (void)
 Releases all the resources allocates in the library. More...
 
SB_INLINE sb_t_version sb_version (int major, int minor, int vminor, int build_major)
 Inline constructor of structure sb_t_version. More...
 
int sb_version_check (sb_t_version version1, sb_t_version version2)
 Compares two version. More...
 
SB_INLINE sb_t_bgra sb_bgra (unsigned char b, unsigned char g, unsigned char r, unsigned char a)
 Inline constructor of structure sb_t_bgra. More...
 
SB_INLINE sb_t_rgba sb_rgba (unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 Inline constructor of structure sb_t_rgba. More...
 
sb_t_err sb_get_info (sb_t_info **const info, int gpu_info)
 The function gets information about the sb library and the available computational devices. More...
 
sb_t_err sb_destroy_info (sb_t_info **const info)
 Destroys the structure. More...
 
sb_t_err sb_format_info (const sb_t_info *const info, char *const str, int str_size)
 Formats the sb library information structure. More...
 
sb_t_err sb_get_uuid (char *const str, size_t size)
 Creates a new uuid. More...
 
sb_t_err sb_get_file_version (sb_t_version *const ver, const char *const file)
 Get the version of a file. More...
 
int sb_is_valid_utf8 (const char *string)
 Check if a string conforms to UTF-8 format. More...
 

Detailed Description

Generic functions.

Macro Definition Documentation

◆ SB_DELIMITER

#define SB_DELIMITER   ";"

Use this define as delimiter.

See also
SB_IMAGE_FILE_EXTENSIONS
SB_FEATURES

Definition at line 5971 of file sb.h.

◆ SB_INIT_NO_LICENSE_KEY

#define SB_INIT_NO_LICENSE_KEY   "NO_KEY"

Use this define with sb_init in order to not manage license keys.

See also
sb_init

Definition at line 5964 of file sb.h.

◆ SB_INIT_ONLY_HW_LICENSE_KEY

#define SB_INIT_ONLY_HW_LICENSE_KEY   "ONLY_HW_KEY"

Use this define with sb_init in order to manage only hardware license keys.

See also
sb_init

Definition at line 5952 of file sb.h.

◆ SB_INIT_ONLY_SB_LICENSE_KEY

#define SB_INIT_ONLY_SB_LICENSE_KEY   "ONLY_SB_KEY"

Use this define with sb_init in order to manage only SqueezeBrains software license keys.

See also
sb_init

Definition at line 5958 of file sb.h.

◆ SB_SURFACE_OPTIONAL_GRAY_LEVEL

#define SB_SURFACE_OPTIONAL_GRAY_LEVEL   128

Gray level for "all model" optional defects.

The optional for all models is used in the event that there are several models and there are parts of the surface that must be optional for all models. Without this it was necessary to exclude the area from the analysis roi.

See also
Labeling with Surface/Deep Surface

Definition at line 6320 of file sb.h.

◆ SB_VALUE_NOT_SET

#define SB_VALUE_NOT_SET   1000000.0f

Value of the prediction in case it is undefined.

For example the field sb_t_sample::weight can take this value.

Definition at line 6261 of file sb.h.

Enumeration Type Documentation

◆ sb_t_device_type

Defines computing device types.

Enumerator
SB_DEVICE_CPU 

CPU device.

SB_DEVICE_GPU 

GPU device.

Definition at line 6106 of file sb.h.

◆ sb_t_floating_point_op_type

Enumerates the floating point precision types to perform operations.

The values are 32 bits both for 32 and 64 bits library version.

Enumerator
SB_FLOATING_POINT_OPS_TYPE_SINGLE_PRECISION 

Single Precision (FP32).

SB_FLOATING_POINT_OPS_TYPE_HALF_PRECISION 

Half Precision (FP16).

Definition at line 6388 of file sb.h.

◆ sb_t_interpolation_mode

Enumerates the interpolation modes.

The values are 32 bits both for 32 and 64 bits library version.

See also
sb_image_resize
sb_image_rotate
Enumerator
SB_INTERPOLATION_MODE_BILINEAR 

Bilinear interpolation.

SB_INTERPOLATION_MODE_NN 

Nearest Neighbor pixel interpolation.

Definition at line 6378 of file sb.h.

Function Documentation

◆ sb_bgra()

SB_INLINE sb_t_bgra sb_bgra ( unsigned char  b,
unsigned char  g,
unsigned char  r,
unsigned char  a 
)

Inline constructor of structure sb_t_bgra.

Parameters
[in]bblue component of color
[in]ggreen component of color
[in]rred component of color
[in]atransparency of color
Returns
The structure sb_t_bgra

Definition at line 6214 of file sb.h.

◆ sb_destroy_info()

sb_t_err sb_destroy_info ( sb_t_info **const  info)

Destroys the structure.

Parameters
[in,out]infoPointer to the parameters structure.
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.
See also
sb_get_info

◆ sb_format_info()

sb_t_err sb_format_info ( const sb_t_info *const  info,
char *const  str,
int  str_size 
)

Formats the sb library information structure.

Interprets the contents of info and converts it to a C-string containing a human-readable version of the corresponding structure.

Parameters
[in]infoPointer to the structure of the sb library information.
[out]strString filled by the function.
[in]str_sizeSize, in bytes, of str
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.

◆ sb_get_file_version()

sb_t_err sb_get_file_version ( sb_t_version *const  ver,
const char *const  file 
)

Get the version of a file.

The implementation is operative system dependent:

  • windows: the version is a property of the file
  • linux: the version is written in the extension of the file, i.e. libcuda.so.495.29.05 has version 495.29.05.-1
    Parameters
    [out]verPointer to version structure
    [in]fileFile name
    Returns
    If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.

◆ sb_get_info()

sb_t_err sb_get_info ( sb_t_info **const  info,
int  gpu_info 
)

The function gets information about the sb library and the available computational devices.

Parameters
[out]infoPointer of the structure.
The pointer must be destroyed with the function sb_destroy_info .
[in]gpu_infoSet to a non-zero value to also get the gpu information.
The function takes a long time to get gpu information, about 15/20 ms.
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.
See also
sb_destroy_info

◆ sb_get_uuid()

sb_t_err sb_get_uuid ( char *const  str,
size_t  size 
)

Creates a new uuid.

It is the standard UUID without the characters '-', for example f2a2c03ddab7d54b912954a05038e94d. It is a string of 32 characters and each of them has a value in the intervalls: 0-9, a-z.

Parameters
[out]strPointer to the string
[in]sizeSize of the string, must be greater or equal than 33 (32 characters plus the string terminator)
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.

◆ sb_init()

sb_t_err sb_init ( const char *const  license_file)

Initializes the SB library.

The function initializes all the functionalities of the library including the license. There is no problem if you call the function more than once without calling sb_release .
After this function you should call the sb_init_dl function if you need to enable the sb_project_detection and sb_svl_run functions for the Deep Surface and Deep Cortex projects.

Attention
This function MUST be called before each other functions of the SB library
Warning
If you are using the sb.dll on windows system, it is advised not to call the function sb_init inside the dllMain, otherwise, you will introduce the possibility that your application deadlocks or crashes. See https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx#general_best_practices for more information.
Parameters
[in]license_fileLicense file. You can use one of the following:
  1. License file (".lic" extension).
    Remenber that in case of demo license you need an active internet connection.
  2. License file and SB_INIT_ONLY_SB_LICENSE_KEY, separated by the SB_DELIMITER character, if you want to manage only SqueezeBrains software keys. for example sb_init("sb.lic;" SB_INIT_ONLY_SB_LICENSE_KEY) which corrispond to sb_init("sb.lic;ONLY_SB_KEY")
  3. Use SB_INIT_ONLY_HW_LICENSE_KEY if you want to manage only USB dongle keys.
    In this case the ethernet client that queries the license manager is not installed, so as not to send any TCP / IP packet on the ethernet network.
  4. Use SB_INIT_NO_LICENSE_KEY if you don't want to manage any license.

If license_file is NULL or it is an empty string or the file doesn't exists, the license manager is installed anyway, it asks the license to the license server and it searches for USB dongle key.

Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.
See also
License
sb_release
sb_init_dl

◆ sb_init_dl()

sb_t_err sb_init_dl ( const char *const  search_path)

Initialize the Deep Learning library.

The function must be called after the sb_init function.
The function enables the sb_project_detection and sb_svl_run functions for the Deep Surface and Deep Cortex projects.

Returns
If successful, returns SB_ERR_NONE.
If library dependencies are not satified, SB_ERR_LIBRARY_DEPENDENCIES. Otherwise, it returns an error code sb_t_err.
The function looks for the SB Deep Learning Framework dependencies in the following folders:
  • Windows
    • current directory, returned by GetCurrentDirectory
    • folder where the executable is located, returned by GetModuleFileName
    • all the folders specified in the environment variable PATH
    • all the folders specified in the variable search_path
  • Linux
    • all the folders specified in the environment variable LD_LIBRARY_PATH
    • /usr/lib/x86_64-linux-gnu, tipically where libcuda.so is located
    • all the folders specified in the environment variable PATH
Parameters
[in]search_pathThe variable allows the user to specify additional folders where to find the SB Deep Learning Framework dependencies in addition to the default ones. Multiple folders paths must be separated by SB_DELIMITER. It can be NULL.
Used only on Windows.
See also
sb_init

◆ sb_is_valid_utf8()

int sb_is_valid_utf8 ( const char *  string)

Check if a string conforms to UTF-8 format.

Sb library does not manage string which are not in UTF-8 format.

Parameters
[in]stringString to check
Returns
Returns 1 if the string conforms to UTF-8 format, otherwise 0.

◆ sb_release()

sb_t_err sb_release ( void  )

Releases all the resources allocates in the library.

There is no problem if you call the function more than once without calling sb_init.

Warning
If you are using the sb.dll on windows system, it is advised not to call the function sb_release inside the dllMain, otherwise, you will introduce the possibility that your application deadlocks or crashes. See https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx#general_best_practices for more information. Anyway, if you call sb_release from dllMain, it is necessary to put the file hasp_rt.exe together with sb.dll.
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.
See also
sb_init

◆ sb_rgba()

SB_INLINE sb_t_rgba sb_rgba ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

Inline constructor of structure sb_t_rgba.

Parameters
[in]rred component of color
[in]ggreen component of color
[in]bblue component of color
[in]atransparency of color
Returns
The structure sb_t_bgra

Definition at line 6247 of file sb.h.

◆ sb_version()

SB_INLINE sb_t_version sb_version ( int  major,
int  minor,
int  vminor,
int  build_major 
)

Inline constructor of structure sb_t_version.

Parameters
[in]major
[in]minor
[in]vminor
[in]build_major
Returns
The structure sb_t_version

Definition at line 6064 of file sb.h.

◆ sb_version_check()

int sb_version_check ( sb_t_version  version1,
sb_t_version  version2 
)

Compares two version.

Parameters
[in]version1First version to compare.
The value of a fields if you don't want to compare the field.
The function breaks the comparison with the first field which is -1.
i.e. if you don't want to compare the field build_major set major.minor.vminor.-1
[in]version2Second version to compare
Returns
The routine compares the elements and returns one of the following values:
  • 0 if version1 is equivalent to version2
  • 1 if version1 is greater than version2
  • -1 if version1 is less than version2