39#include "../common/common.h"
46 long long last_time_ms;
52 char device_info_msg[512] =
"";
60 sprintf(device_info_msg,
", device=\"%s-%s\", memory=%lld/%lldMByte",
67 if (ud->last_time_ms < res->
time_ms)
69 ud->last_time_ms = res->
time_ms + 500;
73 printf(
"\r\"%s\", epoch=%d/%d, loss=%f, accuracy=%f, time left= %llds, time=%llds, time last improvement=%llds (%llds), memory=%lld/%lldMByte%s ",
82 printf(
"\r\"%s\", time=%llds, memory=%lld/%lldMByte ",
95#if defined(_WIN32) && !defined(QT_CREATOR)
97static DWORD WINAPI deep_surface_svl(LPVOID svl)
100 printf(
">>> START SVL <<<\n");
102 printf(
"\n>>> STOP SVL <<<\n");
105 printf(
"sb_svl_run returns %d - %s", err,
sb_err_format(err));
132#define MODEL_NAME "stripe"
144 printf(
"Initialize the SqueezeBrains library\n");
162 printf(
"wait for license...\n");
180 printf(
"Release SqueezeBrains library\n");
183 printf(
"Press ENTER to terminate\n");
213 char img_name_no_ext[256];
214 char img_defects_name_no_ext[256];
220 for (
int i = 0; i < folder_defects->
n; i++)
224 if (strcmp(img_name_no_ext, img_defects_name_no_ext) == 0)
249 for(i = 0; i < folder->
n; i++)
261 for (i = 0; i < folder->
n; i++)
350#if defined(_WIN32) && !defined(QT_CREATOR)
351 printf(
"-------------------------------------------------------------------------------------\n");
352 printf(
"CTRL-right + F12 = stop svl\n");
353 printf(
"-------------------------------------------------------------------------------------\n");
356 int stop_request = 0;
357 CreateThread(NULL, 0, deep_surface_svl, svl, 0, NULL);
364 if (!stop_request && (GetAsyncKeyState(VK_RCONTROL) & 0x8000) && (GetAsyncKeyState(VK_F12) & 0x8000))
366 printf(
"\nSend stop request to svl...\n");
370 if (!svl_run) {
break;}
381 printf(
"\nsaving SVL results....\n");
EXTERN_C sb_t_err wait_license(void)
The functions wait until the license status is active.
#define CHECK_FN_GOTO(function)
sb_t_err check_labeling_file_exists(char *img_file, sb_t_folder *folder_defects, int *file_index)
Check if a labeling mask file exists for the specified image.
sb_t_err create_deep_surface_project_file(SB_HANDLE *deep_surface)
Create a solution file with a Deep Surface project.
sb_t_err set_labeling(SB_HANDLE deep_surface)
Set labeling.
sb_t_err execute_training(void)
Execute training.
sb_t_err
Errors code enum.
const char * sb_err_format(sb_t_err code)
Returns the error message.
sb_t_err sb_file_extract_name(const char *const full, int with_ext, char *const name, int name_size)
Extracts the file name from the full file path.
sb_t_err sb_folder_destroy(sb_t_folder **folder)
Frees all the resources of the sb_t_folder structure.
sb_t_err sb_folder_load(sb_t_folder **const f, const char *const path, const char *const ext, int sort, int verbosity)
Creates the list of the name of the files in a specified folder.
sb_t_err sb_destroy_info(sb_t_info **const info)
Destroys the structure.
sb_t_err sb_release(void)
Releases all the resources allocates in the library.
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.
sb_t_err sb_init(const char *const license_file)
Initializes the SB library.
sb_t_err sb_init_dl(const char *const search_path, sb_t_dl_library_type lib_type)
Initialize the Deep Learning library.
void * SB_HANDLE
HANDLE definition.
@ SB_DL_LIBRARY_PYTORCH
Pytorch library.
@ SB_DL_LIBRARY_OPENVINO
Openvino library. Can be used only for inference with sb_project_detection function.
@ SB_DEVICE_GPU_NVIDIA
GPU NVidia device.
SB_INLINE sb_t_rect sb_rect(int x, int y, int width, int height)
Inline constructor of structure sb_t_rect.
sb_t_err sb_image_info_set_roi(SB_HANDLE image_info, const sb_t_roi *const roi)
Sets the ROI in a SqueezeBrains image info handle.
sb_t_err sb_image_info_set_type(SB_HANDLE image_info, sb_t_image_info_type type)
Sets the type of the SqueezeBrains image info.
sb_t_err sb_image_info_get_roi(SB_HANDLE image_info, sb_t_roi **const roi, int width, int height, int compressed)
Gets the ROI from a SqueezeBrains image info handle.
sb_t_err sb_image_info_get_roi_defects(SB_HANDLE image_info, sb_t_roi **const defects, int width, int height, int compressed)
Gets the surface defects ROI from a SqueezeBrains image info handle.
sb_t_err sb_image_info_load(SB_HANDLE *image_info, const char *const image_file, SB_HANDLE module_handle)
Creates a SqueezeBrains image info handle.
#define SB_IMAGE_INFO_EXT
Extension of the image information file associated to an image.
sb_t_err sb_image_info_set_roi_defects(SB_HANDLE image_info, const sb_t_roi *const defects)
Sets the surface defects ROI on a SqueezeBrains image info handle.
sb_t_err sb_image_info_reset(SB_HANDLE image_info)
Erases all the data from the SqueezeBrains image info handle.
sb_t_err sb_image_info_destroy(SB_HANDLE *image_info)
Destroys the SqueezeBrains image info handle.
sb_t_err sb_image_info_save(SB_HANDLE image_info)
Saves the SqueezeBrains image info handle into the image file.
@ SB_IMAGE_INFO_TYPE_SVL
Image is used for SVL and not used for training.
#define SB_IMAGE_FILE_EXTENSIONS
List of the possible extensions of the image.
sb_t_err sb_image_copy(const sb_t_image *const src, sb_t_image *const dst)
Copies the image.
sb_t_err sb_image_destroy(sb_t_image **const pimg)
Destroys the image.
sb_t_err sb_image_load(sb_t_image **const img, const char *const file)
Loads an image from a file.
const char * sb_device_type_format(sb_t_device_type type)
Returns the string of the device type.
sb_t_err sb_par_add_model(sb_t_par *const par, const char *const model_name)
Adds the model to the parameter structure.
sb_t_err sb_par_destroy(sb_t_par **const par)
Destroys the project parameters structure.
sb_t_err sb_project_set_par(SB_HANDLE handle, const sb_t_par *const par)
Sets the parameters structure into the project handle.
sb_t_err sb_project_create(SB_HANDLE *phandle, const char *const project_name, sb_t_project_type project_type)
Creates a new project of the specifed type.
sb_t_err sb_project_save(SB_HANDLE handle, const char *const solution_file, sb_t_project_mode mode)
Saves the project to file.
sb_t_err sb_project_load(SB_HANDLE *phandle, const char *const solution_file, const char *const project_uuid, sb_t_project_mode mode)
Loads an existing project from a solution file.
sb_t_err sb_project_destroy(SB_HANDLE *phandle)
Frees all the resources of the project handle.
sb_t_err sb_project_get_par(SB_HANDLE handle, sb_t_par **const par)
Retrieves the project parameters structure.
@ SB_PROJECT_MODE_DETECTION_AND_SVL
Load/save all the module information.
@ SB_PROJECT_TYPE_DEEP_SURFACE
Project Deep Surface.
sb_t_err sb_roi_set_rect(sb_t_roi *const roi, unsigned char gl, sb_t_rect rect, int reset_roi)
Sets a rectangular ROI.
sb_t_err sb_roi_destroy(sb_t_roi **const roi)
Destroys the ROI.
sb_t_err sb_solution_get_info(const char *const solution_file, sb_t_solution_info **const solution)
Returns the information contained in the solution_file.
#define SB_SOLUTION_EXT
Extension of the SqueezeBrains solution file.
sb_t_err sb_solution_destroy_info(sb_t_solution_info **const solution)
Destroys the structure of the solution information.
sb_t_err sb_svl_stop_request(SB_HANDLE handle)
Sends a request to the SVL for stop.
sb_t_err sb_svl_destroy_res(sb_t_svl_res **const res)
Destroys the structure of the results of SVL.
sb_t_err sb_svl_reset(SB_HANDLE handle)
Resets the history of previous executions of the SVL.
#define SB_SVL_STEP_FINISHED
SVL step: svl has finished.
sb_t_err sb_svl_run(SB_HANDLE handle)
Runs the SVL.
sb_t_err sb_svl_get_res(SB_HANDLE handle, sb_t_svl_res **const res)
Retrieves the results of SVL.
@ SB_NETWORK_TYPE_SDINET0
Deep Learning Surface Defects Inspection Network 0 with variable input size.
Information about a computing device.
sb_t_memory_info memory
Memory information about the device and its process.
char name[128]
Device name.
sb_t_device_type type
Device type.
int size
Number of available devices.
sb_t_device_info * device
Array of devices.
int id[SB_DEVICES_MAX_NUMBER]
Identifier of the devices to be used.
sb_t_device_type type
Device type.
char name[256]
Name of the file included of path.
defines the list of the file in a folder.
sb_t_file * file
Array of files.
int n
Number of elements of the array file.
int width
Width, in pixel, of the image.
int height
Height, in pixel, of the image.
General information about sb library and computing devices like CPU and GPUs.
sb_t_devices_info devices
List of available computing devices.
char compile_time[32]
String with the compilation time of the sb library.
signed long long malloc_size
Current allocated memory, expressed in bytes, by sb the library.
signed long long malloc_size_max
Maximum allocated memory, expressed in bytes, by sb the library.
char compile_date[32]
String with the compilation date of the sb library.
char version_str[16]
String with the version of the sb library.
signed long long system_total
system physical memory, in bytes
signed long long system_used
system used physical memory, in bytes
sb_t_svl_par svl
SVL parameters.
char uuid[SB_PROJECT_UUID_LEN]
Project UUID.
sb_t_project_info * info
Array of solution project information.
sb_t_image * img
8bit BW image.
sb_t_projects_info projects
Array of the projects info.
int current_project
Index of the current project in the projects array.
sb_t_network_type type
Network type.
sb_t_range angle_range
Angular range, in degrees, for random rotation.
float shift_horizontal
Maximum shift along x-axis.
int flip_horizontal
Flip around horizontal axis.
float shift_vertical
Maximum shift along y-axis.
int flip_vertical
Flip around vertical axis.
int batch_size
Size of the batch used during SVL.
sb_t_svl_dl_par_network network
Network parameters.
int num_epochs
Number of epochs.
sb_t_svl_dl_par_perturbation perturbations
Perturbations for deep learning training.
sb_fp_svl_progress fp_progress
The SVL calls this callback to notify the user the results of SVL.
sb_t_devices_par devices
Devices used for SVL/training.
char project_path[512]
Path of the project, where the SVL will find the images.
void * user_data
Pointer to data which is passed to the callbacks.
sb_t_svl_dl_par dl
Deep Learning SVL parameters.
char image_ext[64]
Extensions of the images.
sb_t_metrics metrics
SVL metrics.
sb_t_svl_res_epoch * epoch
Array of the results of the training epochs.
int size
Number of the elements of the array epoch .
sb_t_svl_res_epochs epochs
Results of training of module based on Deep Learning.
Defines the results of SVL.
sb_t_svl_res_level global
Cumulative results of all levels of all models.
long long time_ms_last_improvement
Time, in ms, when there was the last improvement.
long long time_ms
Execution time, in ms, of SVL.
sb_t_par par
Project parameters.
long long time_left_ms
Estimated time, in ms, left to the end of the SVL.
sb_t_devices_par devices
The devices used to compute the current SVL results.
char running_step[256]
Description of the current step of the training.