SqueezeBrains SDK 1.13
deep_cortex_svl_simple.c
Go to the documentation of this file.
1
39#include "../common/common.h"
40
45
50
55
56#define SAVE_BEST_EPOCH 0
57
61int main(void)
62{
64 sb_t_info* sb_info = NULL;
65 SB_HANDLE deep_cortex = NULL;
66
68 printf("Initialize the SqueezeBrains library\n");
69 CHECK_FN_GOTO(sb_init("../sb.lic"));
70
72#if defined(_WIN32)
73 // "../../../win_x64/dl_framework" is the pre-defined relative path between working directory and SB Deep Learning Framework into the installation folder.
74 CHECK_FN_GOTO(sb_init_dl("../../../win_x64/dl_framework"));
75#else
77#endif
78
79 // Print library version.
80 CHECK_FN_GOTO(sb_get_info(&sb_info, 0));
81 printf("sb ver. %s, compiled on %s %s\n", sb_info->version_str, sb_info->compile_date, sb_info->compile_time);
82
84 printf("wait for license...\n");
86
89
92
95
96FnExit:
98 sb_destroy_info(&sb_info);
99 sb_project_destroy(&deep_cortex);
100
102 printf("Release SqueezeBrains library\n");
103 sb_release();
104
105 printf("Press ENTER to terminate\n");
106 getchar();
107 return (int)err;
108}
109
111{
112 sb_t_err err = SB_ERR_NONE;
113 sb_t_par par;
114
115 // Erase the project file to begin from zero
116 remove("dataset/deep_cortex." SB_SOLUTION_EXT);
117
118 // Create the project file
120 CHECK_FN_GOTO(sb_project_get_par(*deep_cortex, &par));
122 CHECK_FN_GOTO(sb_par_add_model(&par, "peanut"));
123 CHECK_FN_GOTO(sb_par_add_model(&par, "walnut"));
124 CHECK_FN_GOTO(sb_par_add_model(&par, "hazelnut"));
125 CHECK_FN_GOTO(sb_par_add_model(&par, "almond"));
126 CHECK_FN_GOTO(sb_project_set_par(*deep_cortex, &par));
129FnExit:
130 return err;
131}
132
134{
135 sb_t_err err = SB_ERR_NONE;
136 SB_HANDLE image_info = NULL;
137 sb_t_sample sample;
138
142 memset(&sample, 0, sizeof(sample));
143 sample.type = SB_OBJ_TEST;
145 sample.scale = 1.0f;
151 // 1st image
152 CHECK_FN_GOTO(sb_image_info_load(&image_info, "dataset/deep_cortex_peanut.png", deep_cortex));
153 // Reset the image info
156 strcpy(sample.model_name, "peanut");
157 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)));
158 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample));
161 // 2nd image
162 CHECK_FN_GOTO(sb_image_info_load(&image_info, "dataset/deep_cortex_walnut.png", deep_cortex));
163 // Reset the image info
166 strcpy(sample.model_name, "walnut");
167 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)));
168 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample));
171 // 3dh image
172 CHECK_FN_GOTO(sb_image_info_load(&image_info, "dataset/deep_cortex_hazelnut.png", deep_cortex));
173 // Reset the image info
176 strcpy(sample.model_name, "hazelnut");
177 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)));
178 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample));
181 // 4th image
182 CHECK_FN_GOTO(sb_image_info_load(&image_info, "dataset/deep_cortex_almond.png", deep_cortex));
183 // Reset the image info
186 strcpy(sample.model_name, "almond");
187 CHECK_FN_GOTO(sb_get_uuid(sample.uuid, sizeof(sample.uuid)));
188 CHECK_FN_GOTO(sb_image_info_add_sample(image_info, &sample));
191
192FnExit:
193 sb_image_info_destroy(&image_info);
194 return err;
195}
196
198{
199 sb_t_err err = SB_ERR_NONE;
200 SB_HANDLE svl = NULL;
201 sb_t_svl_res* svl_res = NULL;
202 sb_t_par par;
203 sb_t_solution_info* solution = NULL;
204
206 CHECK_FN_GOTO(sb_solution_get_info("dataset/deep_cortex." SB_SOLUTION_EXT, &solution));
217 strcpy(par.svl.project_path, "dataset/");
218 par.svl.dl.num_epochs = 100;
219 par.svl.dl.batch_size = 4;
220 // GPU device for SVL
222 par.svl.devices.id[0] = 0;
223 // dl network parameters
225 // dl perturbation parameters
228 par.svl.dl.perturbations.angle_range.min = -180;
234 printf("Training is running, please wait . . .\n");
237 CHECK_FN_GOTO(sb_svl_get_res(svl, &svl_res));
238 printf("SVL results:\n");
239 printf("\tepoch=%d\n", svl_res->global.epochs.size);
240 printf("\tloss=%f\n", svl_res->global.epochs.epoch[svl_res->global.epochs.size-1].loss);
241 printf("\taccuracy=%f\n", svl_res->global.epochs.epoch[svl_res->global.epochs.size-1].accuracy);
242 printf("\ttime=%1.3fs\n", svl_res->time_ms / 1000.0f);
245FnExit:
247 sb_svl_destroy_res(&svl_res);
248 sb_project_destroy(&svl);
249 sb_solution_destroy_info(&solution);
250 return err;
251}
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 create_deep_cortex_project_file(SB_HANDLE *deep_cortex)
Create a deep_cortex project file.
int main(void)
sb_t_err execute_training(void)
Execute training.
sb_t_err set_model_to_images(SB_HANDLE deep_cortex)
Set samples.
sb_t_err
Errors code enum.
Definition: sb.h:5541
@ SB_ERR_NONE
No errors.
Definition: sb.h:5542
sb_t_err sb_destroy_info(sb_t_info **const info)
Destroys the structure.
sb_t_err sb_init_dl(const char *const search_path)
Initialize the Deep Learning library.
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_get_uuid(char *const str, size_t size)
Creates a new uuid.
@ SB_DEVICE_GPU
GPU device.
Definition: sb.h:6109
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:11931
#define SB_IMAGE_FILE_EXTENSIONS
List of the possible extensions of the image.
Definition: sb.h:7243
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_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_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 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_PROJECT_TYPE_DEEP_CORTEX
Project Deep Cortex.
Definition: sb.h:8878
@ SB_OBJ_TEST
Object is not used for learning.
Definition: sb.h:7972
@ SB_SAMPLE_REQUIRED
Definition: sb.h:8055
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_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.
@ SB_NETWORK_TYPE_ICNET0_64
Deep Learning Image Classification Network 0 with input size 64x64.
Definition: sb.h:9563
int id[SB_DEVICES_MAX_NUMBER]
Identifier of the devices to be used.
Definition: sb.h:10108
sb_t_device_type type
Device type.
Definition: sb.h:10099
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
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
int max
maximum value
Definition: sb.h:5803
int min
minimum value
Definition: sb.h:5802
Sample of an image.
Definition: sb.h:8118
char model_name[SB_PAR_STRING_LEN]
Name of the model.
Definition: sb.h:8191
char uuid[36]
uuid of the sample.
Definition: sb.h:8119
float scale
Scale factor.
Definition: sb.h:8204
sb_t_sample_classify_mode classify_mode
Classification mode.
Definition: sb.h:8273
sb_t_obj_type type
Sample type.
Definition: sb.h:8209
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_t_network_type type
Network type.
Definition: sb.h:9608
sb_t_range angle_range
Angular range, in degrees, for random rotation.
Definition: sb.h:9829
float shift_horizontal
Maximum shift along x-axis.
Definition: sb.h:9813
int flip_horizontal
Flip around y-axis.
Definition: sb.h:9796
float shift_vertical
Maximum shift along y-axis.
Definition: sb.h:9821
int flip_vertical
Flip around x-axis.
Definition: sb.h:9805
int batch_size
Size of the batch used during SVL.
Definition: sb.h:9922
sb_t_svl_dl_par_network network
Network parameters.
Definition: sb.h:9880
int num_epochs
Number of epochs.
Definition: sb.h:9912
sb_t_svl_dl_par_perturbation perturbations
Perturbations for deep learning training.
Definition: sb.h:9895
sb_t_devices_par devices
Devices used for SVL/training.
Definition: sb.h:10192
char project_path[512]
Path of the project, where the SVL will find the images.
Definition: sb.h:10145
sb_t_svl_dl_par dl
Deep Learning SVL parameters.
Definition: sb.h:10204
char image_ext[64]
Extensions of the images.
Definition: sb.h:10153
float loss
SVL loss.
Definition: sb.h:12631
float accuracy
SVL accuracy metric.
Definition: sb.h:12657
sb_t_svl_res_epoch * epoch
Array of the results of the training epochs.
Definition: sb.h:12674
int size
Number of the elements of the array epoch .
Definition: sb.h:12677
sb_t_svl_res_epochs epochs
Results of training of module based on Deep Learning.
Definition: sb.h:12806
Defines the results of SVL.
Definition: sb.h:12877
sb_t_svl_res_level global
Cumulative results of all levels of all models.
Definition: sb.h:12920
long long time_ms
Execution time, in ms, of SVL.
Definition: sb.h:12973