SqueezeBrains SDK 1.13
retina_svl_project.c
Go to the documentation of this file.
1
36#include "../common/common.h"
37
41typedef struct
42{
43 long long last_time_ms;
45
46static sb_t_err svl_callback(void* const user_data, const sb_t_svl_res* const res, int force)
47{
48 sb_t_info* info = NULL;
49 sb_get_info(&info, 0);
50 //Print every 500ms or if "force" flag is set
52 if (ud->last_time_ms < res->time_ms)
53 {
54 ud->last_time_ms = res->time_ms + 1000;
55 printf("\r\"%s\", TP=%d, FP=%d, FN=%d, goodness=%1.3f, cls=\"%s\", features=\"%s\", time=%llds, time last improvement=%llds (%llds), memory=%lld/%lldMByte ",
56 res->running_step,
57 res->global.tp, res->global.fp, res->global.fn, res->global.goodness,
59 res->time_ms / 1000, res->time_ms_last_improvement / 1000, (res->time_ms - res->time_ms_last_improvement) / 1000,
60 info->malloc_size/(1024*1024), info->malloc_size_max/(1024*1024));
61 fflush(stdout);
62 }
63 sb_destroy_info(&info);
65 return(SB_ERR_NONE);
66}
67
68#if defined(_WIN32) && !defined(QT_CREATOR)
69int svl_run;
70static DWORD WINAPI retina_svl(LPVOID svl)
71{
72sb_t_err err;
73 printf(">>> START SVL <<<\n");
74 err = sb_svl_run(svl);
75 printf("\n>>> STOP SVL <<<\n");
76 if (err != SB_ERR_NONE)
77 {
78 printf("sb_svl_run returns %d - %s", err, sb_err_format(err));
79 }
80 svl_run = 0;
81 return 0;
82}
83#endif
84
88int main(int argc, char* argv[])
89{
91 sb_t_info* sb_info = NULL;
92 char path[256] = "solution";
93 int reset = 1;
94 float free_memory_percentage = 0.1f;
95 SB_HANDLE svl = NULL;
96 sb_t_par par;
97 sb_t_folder* folder_cls = NULL;
98 sb_t_svl_res* res = NULL;
99 sb_t_solution_info* solution = NULL;
100 char* program_name = NULL;
101 retina_svl_user_data user_data = {0};
102
103#ifdef _WIN32
104 program_name = strrchr(argv[0], '\\');
105#else
106 program_name = strrchr(argv[0], '/');
107#endif
108 program_name = program_name ? program_name + 1: argv[0];
109
111 sb_init("../sb.lic");
112
114 printf("wait for license...\n");
116
117 CHECK_FN_GOTO(sb_get_info(&sb_info, 0));
118 printf("---------------------------------------------------------------\n");
119 printf("The program run the SVL of the specified project\n");
120 printf("Compiled on: %s %s\n", __DATE__, __TIME__);
121 printf("sb.dll version: %s, compiled on: %s %s\n\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
122 printf("Usage: %s project_path reset free_memory_percentage\n", program_name ? program_name : "");
123 printf(" - project_path:\n");
124 printf(" path of the project\n");
125 printf(" - reset:\n");
126 printf(" 0 svl incremental\n");
127 printf(" 1 svl reset\n");
128 printf(" - free_memory_percentage\n");
129 printf(" When the free physical memory drops below this percentage, the SVL starts to save on disk its data.\n");
130 printf(" Value between 0 and 1\n");
131 printf("---------------------------------------------------------------\n");
132
133 if (argc == 4)
134 {
135 printf("-------------------------------------------------------------------------------------\n");
136 printf("Input parameters:\n");
137 strcpy(path, argv[1]);
138 reset = atoi(argv[2]);
139 free_memory_percentage = (float)atof(argv[3]);
140 }
141 else
142 {
143 printf("---------------------------------------------------------------\n");
144 printf("No parameters found on command line!\n");
145 printf("Runs with default parameter.\n");
146 }
147 printf("project_path : \"%s\"\n", path);
148 printf("reset : %d\n", reset);
149 printf("free_memory_percentage: %f\n", free_memory_percentage);
150 printf("---------------------------------------------------------------\n");
151
153 CHECK_FN_GOTO(sb_folder_load(&folder_cls, path, SB_SOLUTION_EXT, 0, 0))
154 if (folder_cls->n == 0)
155 {
156 printf("No %s file found\n", SB_SOLUTION_EXT);
158 goto FnExit;
159 }
160
162 CHECK_FN_GOTO(sb_solution_get_info(folder_cls->file[0].name, &solution));
163
166
167
169 strcpy(par.svl.project_path, path);
170 par.svl.fp_progress = svl_callback;
171 par.svl.free_memory_percentage = free_memory_percentage;
172 par.svl.user_data = &user_data;
173 char str[8192];
174 sb_par_format(&par, str, sizeof(str));
175 printf("%s\n", str);
178
179 if(reset)
180 {
183 }
184
185#if defined(_WIN32) && !defined(QT_CREATOR)
186 printf("-------------------------------------------------------------------------------------\n");
187 printf("CTRL-right + F12 = stop svl\n");
188 printf("-------------------------------------------------------------------------------------\n");
190 svl_run = 1;
191 int stop_request = 0;
192 CreateThread(NULL, 0, retina_svl, svl, 0, NULL);
194 //With WINDOWS Visual Studio it is possibile to check the keyborad without waiting enter to be pressed
195 while(1)
196 {
197 Sleep(100);
198 //Check the keyborad without waiting enter to be pressed
199 if (!stop_request && (GetAsyncKeyState(VK_RCONTROL) & 0x8000) && (GetAsyncKeyState(VK_F12) & 0x8000))
200 {
201 printf("\nSend stop request to svl...\n");
203 stop_request = 1;
204 }
205 if (!svl_run) { break;}
206 }
207#else
210#endif
211
213 CHECK_FN_GOTO(sb_svl_get_res(svl, &res))
214 if (strcmp(res->running_step, SB_SVL_STEP_FINISHED) == 0)
215 {
216 printf("\nsaving SVL results....\n");
218 }
219
220FnExit:
222 sb_destroy_info(&sb_info);
223 sb_project_destroy(&svl);
224 sb_svl_destroy_res(&res);
225 sb_folder_destroy(&folder_cls);
226 sb_solution_destroy_info(&solution);
227
229 printf("Release SqueezeBrains library\n");
230 sb_release();
231
232 printf("Press ENTER to terminate\n");
233 getchar();
234 return (int)err;
235}
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:5541
const char * sb_err_format(sb_t_err code)
Returns the error message.
@ SB_ERR_NONE
No errors.
Definition: sb.h:5542
@ SB_ERR_FILE_NOT_EXIST
The file doesn't exist.
Definition: sb.h:5574
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_init(const char *const license_file)
Initializes the SB library.
void * SB_HANDLE
HANDLE definition.
Definition: sb.h:6042
sb_t_err sb_get_info(sb_t_info **const info, int gpu_info)
The function gets information about the sb library and the available computational devices.
sb_t_err sb_par_format(const sb_t_par *const par, char *const str, int str_size)
Formats the 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_get_par(SB_HANDLE handle, sb_t_par *const par)
Retrieves the project parameters structure.
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 file.
sb_t_err sb_project_destroy(SB_HANDLE *phandle)
Frees all the resources of the project handle.
@ SB_PROJECT_MODE_DETECTION_AND_SVL
Load/save all the module information.
Definition: sb.h:9027
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:8925
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.
Definition: sb.h:12856
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(int argc, char *argv[])
char name[256]
Name of the file included of path.
Definition: sb.h:6578
defines the list of the file in a folder.
Definition: sb.h:6586
sb_t_file * file
Array of files.
Definition: sb.h:6587
int n
Number of elements of the array file.
Definition: sb.h:6588
General information about sb library and computing devices like CPU and GPUs.
Definition: sb.h:6180
char compile_time[32]
String with the compilation time of the sb library.
Definition: sb.h:6184
signed long long malloc_size
Current allocated memory, expressed in bytes, by sb the library.
Definition: sb.h:6185
signed long long malloc_size_max
Maximum allocated memory, expressed in bytes, by sb the library.
Definition: sb.h:6186
char compile_date[32]
String with the compilation date of the sb library.
Definition: sb.h:6183
char version_str[16]
String with the version of the sb library.
Definition: sb.h:6182
Project parameters.
Definition: sb.h:10647
sb_t_svl_par svl
SVL parameters.
Definition: sb.h:10763
char uuid[SB_PROJECT_UUID_LEN]
Project UUID.
Definition: sb.h:8901
sb_t_project_info * info
Array of solution project information.
Definition: sb.h:8911
Solution info structure.
Definition: sb.h:8931
sb_t_projects_info projects
Array of the projects info.
Definition: sb.h:8932
int current_project
Index of the current project in the projects array.
Definition: sb.h:8933
sb_fp_svl_progress fp_progress
The SVL calls this callback to notify the user the results of SVL.
Definition: sb.h:10128
float free_memory_percentage
Percentage of system memory that the svl tries to leave free.
Definition: sb.h:10160
char project_path[512]
Path of the project, where the SVL will find the images.
Definition: sb.h:10145
void * user_data
Pointer to data which is passed to the callbacks.
Definition: sb.h:10140
float goodness
Goodness of the training.
Definition: sb.h:12701
int fn
Number of FALSE NEGATIVE samples.
Definition: sb.h:12736
int tp
Number of TRUE POSITIVE samples.
Definition: sb.h:12721
char features[SB_PAR_FEATURES_NAMES_LEN]
List of the features choosen by SVL.
Definition: sb.h:12791
char classificator[32]
Classificator choosen by SVL.
Definition: sb.h:12785
int fp
Number of FALSE POSITIVE samples.
Definition: sb.h:12726
sb_t_svl_res_level global
Cumulative results of all levels.
Definition: sb.h:12833
sb_t_svl_res_model model[SB_PAR_MODELS_NUM]
Specific results for each model.
Definition: sb.h:12844
Defines the results of SVL.
Definition: sb.h:12877
sb_t_svl_res_models models
Results for each model.
Definition: sb.h:12916
sb_t_svl_res_level global
Cumulative results of all levels of all models.
Definition: sb.h:12920
long long time_ms_last_improvement
Time, in ms, when there was the last improvement.
Definition: sb.h:12979
long long time_ms
Execution time, in ms, of SVL.
Definition: sb.h:12973
char running_step[256]
Description of the current step of the training.
Definition: sb.h:12907