SqueezeBrains SDK 1.13
|
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 modules parameters. More... | |
struct | sb_t_svl_dl_par_perturbation |
Describes the perturbation of the image / defect. 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 lenght, in byte, of the features names string. | |
#define | SB_DL_WEIGHTS_EXT "weights" |
Extension of the SqueezeBrains pre-trained network weights 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_loss_fn_type_format (sb_t_loss_fn_type type) |
Returns the string of the loss function type. 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... | |
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. |
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. |
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_331 | Deep Learning Surface Defects Inspection Network 0 with input size 331x331.
|
SB_NETWORK_TYPE_SDINET0_331x128 | Deep Learning Surface Defects Inspection Network 0 with input size 331x128.
|
SB_NETWORK_TYPE_SDINET0_400x160 | Deep Learning Surface Defects Inspection Network 0 with input size 400x160.
|
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.
|
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:
|
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 compatibile with the feature.
[in] | feature | String with the feature name. It should be one of the define SB_RETINA_FEATURE_XY. |
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_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. |
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 eack 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 roi defects 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 |
[in] | handle | Project handle. |
Sends a request to the SVL for stop.
handle | Project handle |