SqueezeBrains SDK 1.18
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_frameworks
 Frameworks list. 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_FRAMEWORKS_MAX_NUMBER   4
 Maximum number of frameworks associable to a device managed by the sb library. 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_DL_SCALE_MIN   0.1f
 
#define SB_DL_SCALE_MAX   32.0f
 
#define SB_DL_SCALE_GRANULARITY   0.01f
 Granularity of the value of sb_t_svl_dl_tiling_par::scale parameter and of sb_project_set_scale_offset_par function parameter.
 
#define SB_SVL_DL_INPUT_SDINET0_SIZE_DEFAULT   331
 Default sb_t_svl_dl_par_network::input_size value for SB_NETWORK_TYPE_SDINET0 network.
 
#define SB_SVL_DL_INPUT_SDINET0_SIZE_MIN   128
 Minimum sb_t_svl_dl_par_network::input_size value for SB_NETWORK_TYPE_SDINET0 network.
 
#define SB_SVL_DL_INPUT_SDINET0_SIZE_MAX   512
 Maximum sb_t_svl_dl_par_network::input_size value for SB_NETWORK_TYPE_SDINET0 network.
 
#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_NUM_TILES_MIN   1
 Minimum value of sb_t_svl_dl_tiling_par::num_tiles parameter.
 
#define SB_SVL_DL_NUM_TILES_MAX   64
 Maximum value of sb_t_svl_dl_tiling_par::num_tiles 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_PERTURBATION_SCALE_MIN   0.0f
 Minimum value of sb_t_svl_dl_par_perturbation::delta_scale parameter.
 
#define SB_SVL_DL_PERTURBATION_SCALE_MAX   0.5f
 Maximum value of sb_t_svl_dl_par_perturbation::delta_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 models" optional defects. More...
 

Typedefs

typedef void * SB_HANDLE
 HANDLE definition.
 

Enumerations

enum  sb_t_dl_library_type { SB_DL_LIBRARY_NONE = 0 , SB_DL_LIBRARY_PYTORCH , SB_DL_LIBRARY_OPENVINO }
 Deep Learning library types. More...
 
enum  sb_t_device_type {
  SB_DEVICE_NONE = -1 , SB_DEVICE_CPU = 0 , SB_DEVICE_GPU_NVIDIA , SB_DEVICE_IGPU_INTEL ,
  SB_DEVICE_DGPU_INTEL
}
 Defines computing device types. More...
 
enum  sb_t_framework_type { SB_FRAMEWORK_TYPE_NONE = 0 , SB_FRAMEWORK_TYPE_SB , SB_FRAMEWORK_TYPE_PYTORCH , SB_FRAMEWORK_TYPE_OPENVINO }
 Defines framework 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, sb_t_dl_library_type lib_type)
 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 dl_devices_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 6685 of file sb.h.

◆ SB_DL_SCALE_MAX

#define SB_DL_SCALE_MAX   32.0f

Maximum value of sb_t_svl_dl_tiling_par::scale parameter and of the sum of sb_t_svl_dl_tiling_par::scale plus the value set with function sb_project_set_scale_offset_par .

Definition at line 7052 of file sb.h.

◆ SB_DL_SCALE_MIN

#define SB_DL_SCALE_MIN   0.1f

Minimum value of sb_t_svl_dl_tiling_par::scale parameter and of the sum of sb_t_svl_dl_tiling_par::scale plus the value set with function sb_project_set_scale_offset_par .

Definition at line 7050 of file sb.h.

◆ SB_FRAMEWORKS_MAX_NUMBER

#define SB_FRAMEWORKS_MAX_NUMBER   4

Maximum number of frameworks associable to a device managed by the sb library.

See also
sb_t_frameworks

Definition at line 6854 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 6678 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 6666 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 6672 of file sb.h.

◆ SB_SURFACE_OPTIONAL_GRAY_LEVEL

#define SB_SURFACE_OPTIONAL_GRAY_LEVEL   128

Gray level for "all models" 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 7101 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 7027 of file sb.h.

Enumeration Type Documentation

◆ sb_t_device_type

Defines computing device types.

Enumerator
SB_DEVICE_NONE 

Device not defined.

SB_DEVICE_CPU 

CPU generic device.

SB_DEVICE_GPU_NVIDIA 

GPU NVidia device.

SB_DEVICE_IGPU_INTEL 

GPU Integrated Intel device.

SB_DEVICE_DGPU_INTEL 

GPU Discrete Intel device.

Definition at line 6830 of file sb.h.

◆ sb_t_dl_library_type

Deep Learning library types.

Enumerator
SB_DL_LIBRARY_NONE 

No libraries defined.

SB_DL_LIBRARY_PYTORCH 

Pytorch library.

SB_DL_LIBRARY_OPENVINO 

Openvino library. Can be used only for inference with sb_project_detection function.

Definition at line 6690 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 7169 of file sb.h.

◆ sb_t_framework_type

Defines framework types.

Enumerator
SB_FRAMEWORK_TYPE_NONE 

Framework type None.

SB_FRAMEWORK_TYPE_SB 

Framework type SqueezeBrains. To be used for Retina and Surface projects.

SB_FRAMEWORK_TYPE_PYTORCH 

Framework type Pytorch. To be used for Deep Cortex and Deep Surface projects.

SB_FRAMEWORK_TYPE_OPENVINO 

Frameowrk type Intel OpenVino. To be used for Deep Cortex and Deep Surface projects (detection only).

Definition at line 6842 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 7159 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 6980 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  dl_devices_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]dl_devices_infoSet to a non-zero value to also get the information about devices compatible with SB deep learning extensions.
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 intervals: 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).
    Remember 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 correspond 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,
sb_t_dl_library_type  lib_type 
)

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 satisfied, 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.
[in]lib_typeDeep Learning library to initialize
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 7013 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 6788 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