SqueezeBrains SDK 1.18
deep_cortex_detect.c
Go to the documentation of this file.
1
44#include "../common/common.h"
45
49int main(void)
50{
52 sb_t_info* sb_info = NULL;
53 SB_HANDLE project = NULL;
54 sb_t_image* image = NULL;
55 sb_t_res* res = NULL;
56 sb_t_par* par = NULL;
57 sb_t_folder* folder = NULL;
58 sb_t_solution_info* solution = NULL;
59 int i;
60
62 printf("Initialize the SqueezeBrains library\n");
63 CHECK_FN_GOTO(sb_init("../sb.lic"));
64
66#if defined(_WIN32)
67 // "../../../win_x64/dl_framework" is the pre-defined relative path between working directory and SB Deep Learning Framework into the installation folder.
68 CHECK_FN_GOTO(sb_init_dl("../../../win_x64/dl_framework", SB_DL_LIBRARY_PYTORCH));
69 CHECK_FN_GOTO(sb_init_dl("../../../win_x64/dl_framework", SB_DL_LIBRARY_OPENVINO));
70#else
73#endif
74
75 // Print library version.
76 CHECK_FN_GOTO(sb_get_info(&sb_info, 0));
77 printf("sb ver. %s, compiled on %s %s\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
78
80 printf("wait for license...\n");
82
84 CHECK_FN_GOTO(sb_solution_get_info("solution/deep_cortex_tutorial." SB_SOLUTION_EXT, &solution));
86 CHECK_FN_GOTO(sb_project_load(&project, "solution/deep_cortex_tutorial." SB_SOLUTION_EXT, solution->projects.info[solution->current_project].uuid, SB_PROJECT_MODE_DETECTION_ONLY));
89 CHECK_FN_GOTO(sb_project_get_par(project, &par));
90 par->devices.type = SB_DEVICE_GPU_NVIDIA; // set GPU device
91 par->devices.id[0] = 0; // set the first GPU detected on the machine (with index 0)
92 CHECK_FN_GOTO(sb_project_set_par(project, par));
93 CHECK_FN_GOTO(sb_folder_load(&folder, "dataset", "png", 1, 0));
94 for (i = 0; i < folder->n; i++)
95 {
97 CHECK_FN_GOTO(sb_image_load(&image, folder->file[i].name));
99 CHECK_FN_GOTO(sb_project_detection(project, image, NULL, NULL, NULL));
101 CHECK_FN_GOTO(sb_project_get_res(project, &res, 0));
102 // Print the results
103 printf("image: %s\n", folder->file[i].fname);
104 printf("\t model=\"%s\"\t weight=%f\n", res->samples.sample[0].model_name, res->samples.sample[0].weight);
105 // Destroy the handles.
108 }
109
110FnExit:
112 sb_destroy_info(&sb_info);
113 sb_par_destroy(&par);
114 sb_project_destroy(&project);
115 sb_image_destroy(&image);
116 sb_res_destroy(&res);
117 sb_folder_destroy(&folder);
118 sb_solution_destroy_info(&solution);
119
121 printf("Release SqueezeBrains library\n");
122 sb_release();
123
124 printf("Press ENTER to terminate\n");
125 getchar();
126 return (int)err;
127}
EXTERN_C sb_t_err wait_license(void)
The functions wait until the license status is active.
Definition: common.c:11
#define CHECK_FN_GOTO(function)
Definition: common.h:34
int main(void)
sb_t_err
Errors code enum.
Definition: sb.h:6230
@ SB_ERR_NONE
No errors.
Definition: sb.h:6231
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.
Definition: sb.h:6766
@ SB_DL_LIBRARY_PYTORCH
Pytorch library.
Definition: sb.h:6693
@ SB_DL_LIBRARY_OPENVINO
Openvino library. Can be used only for inference with sb_project_detection function.
Definition: sb.h:6694
@ SB_DEVICE_GPU_NVIDIA
GPU NVidia device.
Definition: sb.h:6834
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.
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_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_detection(SB_HANDLE handle, const sb_t_image *const img, const sb_t_roi *const roi, const sb_t_roi *const roi_defects, const sb_t_samples *const samples)
Detection function.
sb_t_err sb_project_get_res(SB_HANDLE handle, sb_t_res **const res, int details)
Retrieves the results of the last elaborated image.
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_ONLY
Load/save the minimum module information to allow detection.
Definition: sb.h:9822
sb_t_err sb_res_destroy(sb_t_res **const res)
Destroys the module results structure.
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.
Definition: sb.h:9721
sb_t_err sb_solution_destroy_info(sb_t_solution_info **const solution)
Destroys the structure of the solution information.
int id[SB_DEVICES_MAX_NUMBER]
Identifier of the devices to be used.
Definition: sb.h:11252
sb_t_device_type type
Device type.
Definition: sb.h:11237
char name[256]
Name of the file included of path.
Definition: sb.h:7359
char * fname
Name of file excluded the path.
Definition: sb.h:7360
defines the list of the file in a folder.
Definition: sb.h:7367
sb_t_file * file
Array of files.
Definition: sb.h:7368
int n
Number of elements of the array file.
Definition: sb.h:7369
Defines an image.
Definition: sb.h:8100
General information about sb library and computing devices like CPU and GPUs.
Definition: sb.h:6946
char compile_time[32]
String with the compilation time of the sb library.
Definition: sb.h:6950
char compile_date[32]
String with the compilation date of the sb library.
Definition: sb.h:6949
char version_str[16]
String with the version of the sb library.
Definition: sb.h:6948
Project parameters.
Definition: sb.h:11797
sb_t_devices_par devices
Devices used for detection.
Definition: sb.h:11864
char uuid[SB_PROJECT_UUID_LEN]
Project UUID.
Definition: sb.h:9697
sb_t_project_info * info
Array of solution project information.
Definition: sb.h:9707
Results of detection.
Definition: sb.h:12672
sb_t_samples samples
Samples found in the image.
Definition: sb.h:12692
char model_name[SB_PAR_STRING_LEN]
Name of the model.
Definition: sb.h:8981
float weight
Weight of classification.
Definition: sb.h:9013
sb_t_sample * sample
Pointer to the array of sample. The number of element is sb_t_samples::size .
Definition: sb.h:9168
Solution info structure.
Definition: sb.h:9727
sb_t_projects_info projects
Array of the projects info.
Definition: sb.h:9728
int current_project
Index of the current project in the projects array.
Definition: sb.h:9729