SqueezeBrains SDK 1.18
retina_svl_simple.c
Go to the documentation of this file.
1
34#include "../common/common.h"
35
40
45
50
51#define MODEL_NAME "w"
52
56int main(void)
57{
59 sb_t_info* sb_info = NULL;
60 SB_HANDLE retina = NULL;
61
63 printf("Initialize the SqueezeBrains library\n");
64 CHECK_FN_GOTO(sb_init("../sb.lic"))
65
66 // Print library version.
67 CHECK_FN_GOTO(sb_get_info(&sb_info, 0))
68 printf("sb ver. %s, compiled on %s %s\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
69
71 printf("wait for license...\n");
73
74
76
77
79
80
82
83FnExit:
85 sb_destroy_info(&sb_info);
86 sb_project_destroy(&retina);
87
89 printf("Release SqueezeBrains library\n");
90 sb_release();
91
92 printf("Press ENTER to terminate\n");
93 getchar();
94 return (int)err;
95}
96
98{
100 sb_t_par* par = NULL;
101
102 // Erase the project file to begin from zero
103 remove("../images/wheels." SB_SOLUTION_EXT);
104
105 // Create the project file
107 CHECK_FN_GOTO(sb_project_get_par(*retina, &par))
114 CHECK_FN_GOTO(sb_par_add_model(par, MODEL_NAME))
115 par->models.model[0].obj_size = sb_size(136, 128);
116 par->models.model[0].obj_min_distance = sb_size(100, 128);
117 par->models.model[0].obj_stride_coarse = sb_size(8, 8);
118 par->models.model[0].obj_stride_fine = sb_size(4, 4);
119 par->models.model[0].perturbations.size = 1;
122 CHECK_FN_GOTO(sb_project_set_par(*retina, par))
125FnExit:
126 sb_par_destroy(&par);
127 return err;
128}
129
131{
132 sb_t_err err = SB_ERR_NONE;
133 SB_HANDLE image_info = NULL;
134 sb_t_sample sample;
135
140 memset(&sample, 0, sizeof(sample));
141 sample.type = SB_OBJ_TEST;
143 sample.scale = 1.0f;
144 strcpy(sample.model_name, MODEL_NAME);
150 // first image
151 CHECK_FN_GOTO(sb_image_info_load(&image_info, "../images/001.ppm", retina))
152 // Reset the image info
155 sample.centre = sb_point(78, 141);
156 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)))
157 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample))
158 sample.centre = sb_point(234, 138);
159 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)))
160 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample))
161 sample.centre = sb_point(537, 146);
162 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)))
163 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample))
166 // second image
167 CHECK_FN_GOTO(sb_image_info_load(&image_info, "../images/002.ppm", retina))
168 // Reset the image info
171 sample.centre = sb_point(333, 143);
172 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)))
173 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample))
176 // third image
177 CHECK_FN_GOTO(sb_image_info_load(&image_info, "../images/003.ppm", retina))
178 // Reset the image info
181 sample.centre = sb_point(511, 136);
182 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)))
183 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample))
186FnExit:
187 sb_image_info_destroy(&image_info);
188 return err;
189}
190
192{
193 sb_t_err err = SB_ERR_NONE;
194 SB_HANDLE svl = NULL;
195 sb_t_svl_res* svl_res = NULL;
196 sb_t_par* par = NULL;
197 sb_t_solution_info* solution = NULL;
198
200 CHECK_FN_GOTO(sb_solution_get_info("../images/wheels." SB_SOLUTION_EXT, &solution));
208 strcpy(par->svl.project_path, "../images/");
209 par->svl.sl.goodness_target = 0.8f;
212 printf("Training is running, please wait . . .\n");
215 CHECK_FN_GOTO(sb_svl_get_res(svl, &svl_res))
216 printf("goodness=%f\n", svl_res->global.goodness);
217 printf("time=%1.3fs\n", svl_res->time_ms / 1000.0f);
220FnExit:
222 sb_svl_destroy_res(&svl_res);
223 sb_par_destroy(&par);
224 sb_project_destroy(&svl);
225 sb_solution_destroy_info(&solution);
226 return err;
227}
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
sb_t_err
Errors code enum.
Definition: sb.h:6230
@ SB_ERR_NONE
No errors.
Definition: sb.h:6231
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.
void * SB_HANDLE
HANDLE definition.
Definition: sb.h:6766
sb_t_err sb_get_uuid(char *const str, size_t size)
Creates a new uuid.
SB_INLINE sb_t_point sb_point(int x, int y)
Inline constructor of structure sb_t_point.
Definition: sb.h:6546
SB_INLINE sb_t_size sb_size(int width, int height)
Inline constructor of structure sb_t_size.
Definition: sb.h:6574
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_add_sample(SB_HANDLE image_info, const sb_t_sample *const sample)
Adds a sample into the 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.
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.
Definition: sb.h:13377
#define SB_IMAGE_FILE_EXTENSIONS
List of the possible extensions of the image.
Definition: sb.h:8033
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.
Definition: sb.h:9823
@ SB_PROJECT_TYPE_RETINA
Project Retina.
Definition: sb.h:9670
@ SB_OBJ_TEST
Object is not used for learning.
Definition: sb.h:8762
@ SB_SAMPLE_REQUIRED
Definition: sb.h:8845
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.
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.
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.
int main(void)
sb_t_err set_samples(SB_HANDLE retina)
Set samples.
sb_t_err execute_training(void)
Execute training.
sb_t_err create_retina_project_file(SB_HANDLE *retina)
Create a retina project file.
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
sb_t_par_perturbations perturbations
Perturbations of the samples.
Definition: sb.h:11610
sb_t_size obj_size
Model size.
Definition: sb.h:11576
sb_t_size obj_stride_coarse
Coarse search step.
Definition: sb.h:11668
sb_t_size obj_stride_fine
Fine search step.
Definition: sb.h:11682
sb_t_size obj_min_distance
Minimum distance between two samples.
Definition: sb.h:11653
sb_t_par_model model[SB_PAR_MODELS_NUM]
Array of models.
Definition: sb.h:11738
int flip_vertical
Flip around vertical axis. 3th operation.
Definition: sb.h:11413
int num_synthetic_samples
Number of synthetic sample to generated with a random angle in the range sb_t_par_perturbation::angle...
Definition: sb.h:11428
sb_t_par_perturbation perturbation[SB_PAR_PERTURBATIONS_NUM]
Array of the perturbations.
Definition: sb.h:11442
int size
Number of used elements of the array perturbation.
Definition: sb.h:11447
Project parameters.
Definition: sb.h:11797
sb_t_par_models models
Models parameters.
Definition: sb.h:11804
sb_t_svl_par svl
SVL parameters.
Definition: sb.h:11913
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
Sample of an image.
Definition: sb.h:8908
sb_t_point centre
Coordinates of the centre of the sample.
Definition: sb.h:8916
char model_name[SB_PAR_STRING_LEN]
Name of the model.
Definition: sb.h:8981
char uuid[36]
uuid of the sample.
Definition: sb.h:8909
float scale
Scale factor.
Definition: sb.h:8994
sb_t_sample_classify_mode classify_mode
Classification mode.
Definition: sb.h:9063
sb_t_obj_type type
Sample type.
Definition: sb.h:8999
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
sb_t_svl_sl_par sl
Shallow Learning SVL parameters.
Definition: sb.h:11342
char project_path[512]
Path of the project, where the SVL will find the images.
Definition: sb.h:11289
char image_ext[64]
Extensions of the images.
Definition: sb.h:11297
float goodness
Goodness of the training.
Definition: sb.h:14396
Defines the results of SVL.
Definition: sb.h:14638
sb_t_svl_res_level global
Cumulative results of all levels of all models.
Definition: sb.h:14681
long long time_ms
Execution time, in ms, of SVL.
Definition: sb.h:14740
float goodness_target
Goodness target of the training.
Definition: sb.h:11184