SqueezeBrains SDK 1.18
|
Collection of functions to manage SVL or training of Retina and Surface. More...
Modules | |
Features defines | |
Data Structures | |
struct | sb_t_svl_pre_elaboration |
Contains the results of the image pre-processing. More... | |
struct | sb_t_svl_dl_par_network |
Deep Learning network parameters. More... | |
struct | sb_t_svl_dl_par_perturbation |
Describes the perturbation of the image / defect. More... | |
struct | sb_t_svl_dl_tiling_par |
Image tiling parameters. More... | |
struct | sb_t_svl_dl_par |
SVL parameters to configure the Deep Learning training. More... | |
struct | sb_t_svl_sl_par |
SVL parameters that configure the Shallow Learning training. More... | |
struct | sb_t_devices_par |
Property of computational devices. More... | |
struct | sb_t_svl_par |
SVL parameters. More... | |
struct | sb_t_svl_err |
Contains information regarding the error of the SVL. More... | |
struct | sb_t_svl_res_image |
Defines the results of the elaboration of the SVL of an image. More... | |
struct | sb_t_svl_res_images |
Defines the results of the elaboration of the SVL images. More... | |
struct | sb_t_svl_res_epoch |
Results of a training epoch. More... | |
struct | sb_t_svl_res_epochs |
Results of the training epochs. More... | |
struct | sb_t_svl_res_level |
Results of the SVL of a level per model. More... | |
struct | sb_t_svl_res_levels |
Results of the SVL of a levels processed. More... | |
struct | sb_t_svl_res_model |
Results of the SVL of a specific model. More... | |
struct | sb_t_svl_res_models |
Results of the SVL of a models processed. More... | |
struct | sb_t_svl_res |
Defines the results of SVL. More... | |
Macros | |
#define | SB_PAR_FEATURES_NAMES_LEN 256 |
Maximum length, in byte, of the features names string. | |
#define | SB_PRE_TRAINING_EXT "ptf" |
Extension of the SqueezeBrains pre-training network file. | |
#define | SB_DEVICES_MAX_NUMBER 4 |
Maximum number of computational devices managed by the sb library. More... | |
#define | SB_CLS_0 "cls0" |
classificator type 0 | |
#define | SB_CLS_1 "cls1" |
classificator type 1 | |
#define | SB_FEATURES |
< List of all the features separated by SB_DELIMITER | |
#define | SB_SVL_STEP_INITIALIZATION "initializing data for svl" |
SVL step: initialization. | |
#define | SB_SVL_STEP_SEARCHING_RECIPE "choosing recipe" |
SVL step: choosing recipe. | |
#define | SB_SVL_STEP_TRAINING_RECIPE "training recipe" |
SVL step: training recipe. | |
#define | SB_SVL_STEP_FINALIZATION "finalization of svl" |
SVL step: finalization of svl. | |
#define | SB_SVL_STEP_FINISHED "svl has finished" |
SVL step: svl has finished. | |
Typedefs | |
typedef sb_t_err(* | sb_fp_svl_pre_elaboration) (const SB_HANDLE image_info, void *const user_data, const char *const image_file, int image_index, sb_t_svl_pre_elaboration *const pre_elaboration) |
Definition of the callback for image pre elaboration. More... | |
typedef sb_t_err(* | sb_fp_svl_progress) (void *const user_data, sb_t_svl_res *res, int force) |
Definition of the callback for the working progress. More... | |
typedef sb_t_err(* | sb_fp_svl_command) (void *const user_data, sb_t_svl_res *res, sb_t_svl_command *const command, const char *const msg) |
Definition of the callback that the SVL calls when it needs to know how to continue. More... | |
Functions | |
const char * | sb_svl_command_format (sb_t_svl_command command) |
Returns the string of the SVL command. More... | |
const char * | sb_svl_par_optimization_mode_format (sb_t_svl_par_optimization_mode mode) |
Returns the string of the SVL optimization mode. More... | |
const char * | sb_network_type_format (sb_t_network_type type) |
Returns the string of the network type. More... | |
const char * | sb_network_freeze_mode_format (sb_t_network_freeze_mode freeze_mode) |
Returns the string of the network freeze mode. More... | |
const char * | sb_tiling_mode_format (sb_t_tiling_mode mode) |
Returns the string of the tiling mode. More... | |
const char * | sb_loss_fn_type_format (sb_t_loss_fn_type type) |
Returns the string of the loss function type. More... | |
const char * | sb_image_borders_extension_mode_format (sb_t_image_borders_extension_mode mode) |
Returns the string of the image borders extension mode. More... | |
const char * | sb_perturbation_mode_format (sb_t_perturbation_mode mode) |
Returns the string of the Deep Learning SVL image perturbation mode. More... | |
const char * | sb_perturbation_type_format (sb_t_perturbation_type type) |
Returns the string of the Deep Learning SVL image perturbation type. More... | |
const char * | sb_feature_description (const char *const feature) |
Returns a string with a brief description of a feature. More... | |
sb_t_err | sb_svl_run (SB_HANDLE handle) |
Runs the SVL. More... | |
sb_t_err | sb_svl_reset (SB_HANDLE handle) |
Resets the history of previous executions of the SVL. More... | |
sb_t_err | sb_svl_stop_request (SB_HANDLE handle) |
Sends a request to the SVL for stop. More... | |
sb_t_err | sb_svl_get_res (SB_HANDLE handle, sb_t_svl_res **const res) |
Retrieves the results of SVL. More... | |
sb_t_err | sb_svl_destroy_res (sb_t_svl_res **const res) |
Destroys the structure of the results of SVL. More... | |
sb_t_err | sb_svl_clone_res (sb_t_svl_res **const dst, const sb_t_svl_res *const src) |
Copies the structure of the results of SVL. More... | |
sb_t_err | sb_svl_save_pre_training (SB_HANDLE handle, const char *const file_name) |
Saves the current SVL parameter configuration into a pre-training file. More... | |
sb_t_err | sb_pre_training_get_par (sb_t_par **const par, const char *const file_name) |
Retrieves the project parameter structure of a pre-training file. More... | |
Collection of functions to manage SVL or training of Retina and Surface.
See SVL - training for more information.
#define SB_DEVICES_MAX_NUMBER 4 |
Maximum number of computational devices managed by the sb library.
typedef sb_t_err(* sb_fp_svl_command) (void *const user_data, sb_t_svl_res *res, sb_t_svl_command *const command, const char *const msg) |
Definition of the callback that the SVL calls when it needs to know how to continue.
[in,out] | user_data | Pointer to the user data. |
[in] | res | current results of the SVL. |
[out] | command | Pointer to the SVL command. The user can decided what SVL has to do. |
[in] | msg | Message for the user. |
typedef sb_t_err(* sb_fp_svl_pre_elaboration) (const SB_HANDLE image_info, void *const user_data, const char *const image_file, int image_index, sb_t_svl_pre_elaboration *const pre_elaboration) |
Definition of the callback for image pre elaboration.
[in] | image_info | SqueezeBrains image info handle. |
[in,out] | user_data | Pointer to the user data. |
[in] | image_file | Image file name. |
[in] | image_index | Index of the image. |
[out] | pre_elaboration | Pointer to the structure where the user implements the pre-elaboration of the images and set the ROI |
typedef sb_t_err(* sb_fp_svl_progress) (void *const user_data, sb_t_svl_res *res, int force) |
Definition of the callback for the working progress.
[in,out] | user_data | Pointer to the user data. |
[in] | res | current results of the SVL. |
[in] | force | If different that 0 means that in the results something is changed. |
Enumerate the image borders extension mode.
enum sb_t_loss_fn_type |
Enumerates the loss functions.
Enumerator | |
---|---|
SB_LOSS_FN_TYPE_CCE | Categorical Cross Entropy loss. loss used for (mutual-exclusive) multi-class classification/segmentation task. The loss is computed only considering the error of the model associated to the target instance. The instance is an image, in the case of Deep Cortex project, or a pixel, in the case of Deep Surface. |
SB_LOSS_FN_TYPE_FOCAL | Focal loss. loss used for multi-class classification/segmentation task. The loss is computed only considering the error of the model associated to the target instance. The instance is an image, in the case of Deep Cortex project, or a pixel, in the case of Deep Surface. The particularity of this loss is that the training focuses on target instances harder to disciminate. |
SB_LOSS_FN_TYPE_BCE | SB Binary Cross Entropy loss. loss used for (non-exclusive) multi-class binary classification/segmentation task. The loss is computed considering the error occurred for all the models on the current SVL instance. The instance may have at most one model assigned (or also none) and its loss is equal to the sum of the error on the associated model (higher if it is not detected) and the errors associated to the other models (higher if they are detected). The instance is an image, in the case of Deep Cortex project, or a pixel, in the case of Deep Surface. The loss value at the end of each epoch is obtained by averaging all the loss instances over SVL batch. |
Deep learning network freeze mode.
Enumerator | |
---|---|
SB_NETWORK_FREEZE_MODE_NONE | Freeze mode disabled. No parameters of any layers are frozen. It corresponds to let the network free to learn during the training without any constraint. |
SB_NETWORK_FREEZE_MODE_FIRST_BLOCK | Freeze the first block of the newtork. Only the parameters of the first block of the network are frozen and thus not trainable. Block means a group of layer which performs operation strictly related to each other. |
SB_NETWORK_FREEZE_MODE_ENCODER | Freeze the network encoder. Only encoder parameters are frozen, i.e. all those parameters which contributes to update and extract features from training images. Use this option if you want to fix the set of fetaures and specialize the training on the new dataset only by changing the way in which feautures are combined. |
SB_NETWORK_FREEZE_MODE_ENCODER_DECODER | Freeze both encoder and decoder. Encoder and decoder parameters are frozen. Decoder refers to all those layers used to expand and combine the compressed features at the encoder output in order to get features at higher resolution. This freeze modality does not lock into account the part of the network resposable of genereting the classification associated to each pixel.
|
enum sb_t_network_type |
Deep learning network types.
Enumerator | |
---|---|
SB_NETWORK_TYPE_EFFICIENTNET_B0 | Deep Learning EfficientNet b0.
|
SB_NETWORK_TYPE_EFFICIENTNET_B1 | Deep Learning EfficientNet b1.
|
SB_NETWORK_TYPE_EFFICIENTNET_B2 | Deep Learning EfficientNet b2.
|
SB_NETWORK_TYPE_SDINET0 | Deep Learning Surface Defects Inspection Network 0 with variable input size. |
SB_NETWORK_TYPE_ICNET0_64 | Deep Learning Image Classification Network 0 with input size 64x64.
|
SB_NETWORK_TYPE_ICNET0_128 | Deep Learning Image Classification Network 0 with input size 128x128.
|
SB_NETWORK_TYPE_ODNET0 | Deep Learning Object Detection Network 0 with input size 416x416.
|
Enumerates the mode of the perturbations.
Enumerates the range of application of the perturbations.
Enumerator | |
---|---|
SB_PERTURBATION_TYPE_IMAGE | The whole image is perturbated. |
SB_PERTURBATION_TYPE_DEFECTS | Only the defect area is perturbated. |
SB_PERTURBATION_TYPE_BOTH |
enum sb_t_svl_command |
Enumerates the actions that SVL has to do after a stop.
On a stop the sb_svl_run calls the callback sb_t_svl_par::fp_command.
The values are 32 bits both for 32 and 64 bits library version.
Enumerator | |
---|---|
SB_SVL_COMMAND_STOP | The SVL stops and exits, applying the training to the module. After the sb_svl_run finished, you can call sb_project_save to save the results. |
SB_SVL_COMMAND_CONTINUE | The SVL continues and, if necessary, resets the training. |
SB_SVL_COMMAND_ABORT | The SVL stops and exits, without applying the training reached to the module. After the sb_svl_run finished, You can not call sb_project_save to save the results. |
SB_SVL_COMMAND_CONTINUE_NO_RESET | The SVL continues without reset. |
SB_SVL_COMMAND_NEXT_STEP | The SVL go to next step. |
Describes the optimization mode of SVL.
The values are 32 bits both for 32 and 64 bits library version.
Enumerator | |
---|---|
SB_SVL_PAR_OPTIMIZATION_TIME_SLOW | SVL promotes accuracy with respect to execution time. |
SB_SVL_PAR_OPTIMIZATION_TIME_MEDIUM | |
SB_SVL_PAR_OPTIMIZATION_TIME_FAST | |
SB_SVL_PAR_OPTIMIZATION_USE_SELECTED | SVL will use the features selected by the user and which are compatible with the data set. The user can select the features with the parameter sb_t_svl_sl_par.features. |
enum sb_t_svl_stop_reason |
Enumerates the reasons why SVL is terminated or why the callback sb_t_svl_par::fp_command has been called.
The values are 32 bits both for 32 and 64 bits library version.
See sb_svl_run for the default action in case the sb_t_svl_par::fp_command is not set.
Enumerator | |
---|---|
SB_SVL_STOP_NONE | SVL finishes without errors. |
SB_SVL_STOP_CONFLICT | There are errors which can not be eliminated. The function sb_svl_run calls sb_t_svl_par.fp_command with sb_t_svl_res::stop_reason equal to SB_SVL_STOP_CONFLICT in the following case:
|
SB_SVL_STOP_USER_REQUEST | The user has stopped the SVL. |
SB_SVL_STOP_MEMORY | Insufficient memory to complete the SVL. |
SB_SVL_STOP_RESET_MANDATORY | Request for a mandatory reset of SVL. The function sb_svl_run calls sb_t_svl_par.fp_command with sb_t_svl_res::stop_reason equal to SB_SVL_STOP_RESET_MANDATORY in the following case:
The check for automatic reset is done separately for each model. |
SB_SVL_STOP_RESET_OPTIONAL | Ask for an optional reset of SVL. The function sb_svl_run calls sb_t_svl_par.fp_command with sb_t_svl_res::stop_reason equal to SB_SVL_STOP_RESET_OPTIONAL in the following case:
The check for automatic reset is done separately for each model. |
SB_SVL_STOP_WARNING | Send a warning message. The function sb_svl_run calls sb_t_svl_par.fp_command with sb_t_svl_res::stop_reason equal to SB_SVL_STOP_WARNING in the following case:
|
enum sb_t_tiling_mode |
Enumerates the tiling mode.
"Tiling" refers to that image processing operation that consists in subdividing the elaborated image into multiple sub-images.
Enumerator | |
---|---|
SB_TILING_MODE_MANUAL | Manual tiling. Tiling scheme, i.e. the number of horizontal and vertical tiles, to apply to the images is fixed. |
SB_TILING_MODE_AUTO | Auto tiling. Tiling scheme is automatically applied in according to the sb_t_svl_dl_tiling_par::scale parameter in order to keep constant the pixel/mm ratio used by the algorithm to process the images.
The image below shows the case with 3x2 tiles.
|
const char * sb_feature_description | ( | const char *const | feature | ) |
Returns a string with a brief description of a feature.
In the description returned by the function there is also information about the image format compatible with the feature.
[in] | feature | String with the feature name. It should be one of the define SB_RETINA_FEATURE_XY. |
const char * sb_image_borders_extension_mode_format | ( | sb_t_image_borders_extension_mode | mode | ) |
Returns the string of the image borders extension mode.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding value.
[in] | mode | Image borders extension mode. |
const char * sb_loss_fn_type_format | ( | sb_t_loss_fn_type | type | ) |
Returns the string of the loss function type.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding value.
[in] | type | Loss function type. |
const char * sb_network_freeze_mode_format | ( | sb_t_network_freeze_mode | freeze_mode | ) |
Returns the string of the network freeze mode.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding value.
[in] | freeze_mode | Freeze mode. |
const char * sb_network_type_format | ( | sb_t_network_type | type | ) |
Returns the string of the network type.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding value.
[in] | type | Network type. |
const char * sb_perturbation_mode_format | ( | sb_t_perturbation_mode | mode | ) |
Returns the string of the Deep Learning SVL image perturbation mode.
Interprets the contents of the mode and converts it to a C-string containing a human-readable version of the corresponding perturbation mode.
The string must not be freed.
[in] | mode | Deep Learning SVL image perturbation mode. |
const char * sb_perturbation_type_format | ( | sb_t_perturbation_type | type | ) |
Returns the string of the Deep Learning SVL image perturbation type.
Interprets the contents of the type and converts it to a C-string containing a human-readable version of the corresponding perturbation type.
The string must not be freed.
[in] | type | Deep Learning SVL image perturbation type. |
Retrieves the project parameter structure of a pre-training file.
[in] | file_name | Name of the file. |
[out] | par | Pointer to the parameters structure. On successful return, this parameter will be filled with the pointer to sb_t_par structure. The structure should be freed using the function sb_par_destroy. |
sb_t_err sb_svl_clone_res | ( | sb_t_svl_res **const | dst, |
const sb_t_svl_res *const | src | ||
) |
Copies the structure of the results of SVL.
[out] | dst | The variable will be filled with the pointer of the new structure. |
[in] | src | Pointer of the structure to be copied. |
const char * sb_svl_command_format | ( | sb_t_svl_command | command | ) |
Returns the string of the SVL command.
Interprets the contents of the command and converts it to a C-string containing a human-readable version of the corresponding command.
The string must not be freed.
[in] | command | SVL command. |
sb_t_err sb_svl_destroy_res | ( | sb_t_svl_res **const | res | ) |
Destroys the structure of the results of SVL.
[in,out] | res | Pointer to the structure. It is set to NULL. |
sb_t_err sb_svl_get_res | ( | SB_HANDLE | handle, |
sb_t_svl_res **const | res | ||
) |
Retrieves the results of SVL.
[in] | handle | Project handle. |
[out] | res | Pointer to the structure of SVL results. On successful return, this parameter will be filled with the pointer of the structure sb_t_svl_res. The structure should be freed using the function sb_svl_destroy_res. |
const char * sb_svl_par_optimization_mode_format | ( | sb_t_svl_par_optimization_mode | mode | ) |
Returns the string of the SVL optimization mode.
Interprets the contents of the mode and converts it to a C-string containing a human-readable version of the corresponding mode.
The string must not be freed.
[in] | mode | SVL running mode. |
Resets the history of previous executions of the SVL.
handle | Project handle |
Runs the SVL.
The functions calls some callbacks to interact with the caller. See SVL Callbacks for more information.
The function uses the images in the folder specified with the parameter sb_t_svl_par::project_path.
In particular it uses the images with type equal to SB_IMAGE_INFO_TYPE_SVL , see sb_image_info_set_type.
For each image the function calls the callback sb_t_svl_par::fp_pre_elaboration, if set, otherwise it calls the function sb_image_info_load to get the analysis roi, the samples in case of Retina or Deep Cortex projects, the defects ROI in case of Surface or Deep Surface projects.
In same cases, when the user modifies the SVL parameters or the dataset, a reset of the training may be required. There are also a set of conditions in which the reset is only optional and the final decision is left to the user using the callback sb_t_svl_par::fp_command.
If the callback sb_t_svl_par::fp_command is not set, the function automatically manages the particular situations that occur during training.
The table below shows what the function does depending on the value of the sb_t_svl_res::stop_reason parameter:
sb_t_svl_res::stop_reason | action |
SB_SVL_STOP_CONFLICT | stop |
SB_SVL_STOP_USER_REQUEST | stop |
SB_SVL_STOP_MEMORY | stop |
SB_SVL_STOP_RESET_MANDATORY | reset |
SB_SVL_STOP_RESET_OPTIONAL | reset |
SB_SVL_STOP_WARNING | continue, Retina or Surface stop, Deep Cortex or Deep Surface |
If you need to do the detection using Intel OpenVino technology on a device between SB_DEVICE_CPU , SB_DEVICE_IGPU_INTEL or SB_DEVICE_DGPU_INTEL , you have to call sb_project_openvino_conversion function after sb_svl_run in order to generate the openvino weights.
[in] | handle | Project handle. |
Saves the current SVL parameter configuration into a pre-training file.
It is possible to load the saved training parameters and used as pre-training for next SVL on different projects.
It works only for Deep Cortex and Deep Surface projects.
[in] | handle | Project handle. |
[in] | file_name | Name of the file. We recommend using the SB_PRE_TRAINING_EXT extension. |
Sends a request to the SVL for stop.
handle | Project handle |
const char * sb_tiling_mode_format | ( | sb_t_tiling_mode | mode | ) |
Returns the string of the tiling mode.
Interprets the contents of the code and converts it to a C-string containing a human-readable version of the corresponding value.
[in] | mode | Tiling mode. |