SqueezeBrains SDK 1.13
DeepCortexDetect.cs
1using System;
2using sb_cs;
3using Tutorials_Common;
4
6{
39 {
40 static SbError execute()
41 {
42 SbProject prj = null;
43 SbImage img = null;
44 SbError err = SbError.SB_ERR_NONE;
45
47 Console.WriteLine("Sb Init");
48 err = Sb.Init("../../../sb.lic");
49 if (err != SbError.SB_ERR_NONE)
50 {
51 Console.WriteLine("Sb.Init failed with error " + err);
52 return err;
53 }
54
56 Console.WriteLine("Wait for license...");
57 err = Common.WaitLicense();
58 if (err != SbError.SB_ERR_NONE)
59 {
60 Console.WriteLine("SbLicense.WaitLicense failed with error " + err);
61 goto FnExit;
62 }
63
65 err = Sb.InitDl("../../../../../win_x64/dl_framework");
66 if (err != SbError.SB_ERR_NONE)
67 {
68 Console.WriteLine("Sb.InitDl failed with error " + err);
69 return err;
70 }
71
73 String solution_file = "../../solution/deep_cortex_tutorial." + SbDefines.SbSolutionExt;
74 SbSolutionInfo solutionInfo = SbSolution.GetInfo(solution_file);
75 if (solutionInfo == null || solutionInfo.Error() != SbError.SB_ERR_NONE)
76 {
77 err = solutionInfo == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : solutionInfo.Error();
78 Console.WriteLine("SbSolution.GetInfo failed");
79 goto FnExit;
80 }
81 else if (solutionInfo.projects.Length == 0)
82 {
83 err = SbError.SB_ERR_PROJECT_NOT_FOUND;
84 Console.WriteLine("SbSolution.GetInfo no projects found");
85 goto FnExit;
86 }
87 Console.WriteLine("GetInfo, found " + solutionInfo.projects.Length + " project/s");
88
90 prj = SbProject.Load(solution_file, solutionInfo.projects[0].uuid, SbProjectMode.SB_PROJECT_MODE_DETECTION_ONLY);
91 if (prj == null || prj.Error() != SbError.SB_ERR_NONE)
92 {
93 err = prj == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
94 Console.WriteLine("SbProject.Load failed with error " + err);
95 goto FnExit;
96 }
97
100 SbPar par = prj.GetPar();
101 par.devices.type = SbDeviceType.SB_DEVICE_GPU; // set GPU device
102 par.devices.id[0] = 0; // set the first GPU founded on the machine (with index 0)
103 err = prj.SetPar(par);
104 if (err != SbError.SB_ERR_NONE || prj.Error() != SbError.SB_ERR_NONE)
105 {
106 Console.WriteLine("SbProject.SetPar failed with error " + err);
107 goto FnExit;
108 }
109
110 SbFolder folder = SbFolder.Load("../../dataset", "png", true, 0);
111 if (folder != null)
112 {
113 for (int i = 0; i < folder.files.Length; i++)
114 {
116 img = SbImage.Load(folder.files[i]);
117 if (img == null || img.Error() != SbError.SB_ERR_NONE)
118 {
119 Console.WriteLine("SbImage.Load " + folder.files[i] + " failed");
120 err = img == null ? SbError.SB_ERR_INTERNAL : img.Error();
121 break;
122 }
123
125 err = prj.Detection(img, null);
126 if (err != SbError.SB_ERR_NONE)
127 {
128 Console.WriteLine("SbProject.Detection failed with error " + err);
129 break;
130 }
131
133 SbRes res = prj.GetRes(false);
134 if (res == null || prj.Error() != SbError.SB_ERR_NONE)
135 {
136 err = res == null ? SbError.SB_ERR_INSUFFICIENT_FREE_MEMORY : prj.Error();
137 Console.WriteLine("SbProject.GetRes failed with error " + err);
138 break;
139 }
140
142 Console.WriteLine("image: " + folder.files[i]);
143 Console.WriteLine("\tmodel=" + res.samples[0].model_name + ",\tweight=" + res.samples[0].weight);
144
145 if (img != null)
146 {
147 img.Dispose();
148 img = null;
149 }
150 }
151 }
152
153 FnExit:
155 if (prj != null)
156 prj.Dispose();
157 if (img != null)
158 img.Dispose();
159
160 Console.WriteLine("Release SqueezeBrains library");
161 Sb.Release();
162
163 Console.WriteLine("Press ENTER to terminate");
164 Console.ReadKey();
165
166 return err;
167 }
168
169 static void Main(string[] args)
170 {
171 execute();
172 }
173 }
174}
Tutorial 3 - Deep Cortex - How to elaborate images
SbError Error()
Returns the error code of the last operation. If no error SbError.SB_ERR_NONE is returned.
Defines class
Definition: cs_common.h:258
static const String SbSolutionExt
Solution file extension
Definition: cs_common.h:264
array< int > id
Identifier of the devices to be used
Definition: cs_par.h:254
SbDeviceType type
Device computational type
Definition: cs_par.h:248
Folder Class that wraps the sb_t_folder structure
Definition: cs_folder.h:16
static SbFolder Load(String^ path, String ^ext, bool sort, int verbosity)
Creates the list of the name of the files in a specified folder.
array< String^> files
Array of files.
Definition: cs_folder.h:22
Sb Main Class
Definition: cs_sb.h:374
static SbError Release()
Releases all the resources allocated in the library
static SbError InitDl(String^ search_path)
Init the Deep Learning SB Library. The function enables the SbProject::Detection and SVL functions fo...
static SbError Init(String ^ license_file)
Init the SB Library. The function initializes all the functionalities of the library including the li...
SbImage class that wraps the sb_t_image structure. You must call the Dispose() method to free all the...
Definition: cs_image.h:66
static SbImage Load(String^ filename)
Loads an image from file.
Parameters Class that wraps the sb_t_par structure. You must call the Dispose() method to free all th...
Definition: cs_par.h:657
SbDevicesPar devices
Devices used for inference.
Definition: cs_par.h:693
Project Class You must call the Dispose() method to free all the resources of the returned instance.
Definition: cs_project.h:44
static SbProject Load(String^ solution_file, String^ project_uuid, SbProjectMode mode)
Loads an existing project from file.
SbRes GetRes(bool details)
Retrieves the results of the last processed image
SbError Detection(SbImage ^img, SbRoi ^roi)
The function elaborates the image inside the ROI. For Surface projects the function computes also the...
SbPar GetPar()
Retrieves the project parameters structure.
SbError SetPar(SbPar^ par)
Sets the project parameters.
Class of the results of the image elaboration with the SbProject::Detection method....
Definition: cs_res.h:225
array< SbSample^> samples
Samples results. Only Retina projects
Definition: cs_res.h:246
Solution class
Definition: cs_solution.h:44
static SbSolutionInfo GetInfo(String^ solution_file)
Returns the information contained in the solution_file.
Solution Info Class that wraps the sb_t_solution_info structure
Definition: cs_solution.h:17
array< SbProjectInfo^> projects
Array of the projects information of the solution. sb_t_solution_info.projects
Definition: cs_solution.h:23
SbError
Enum error codes
Definition: cs_common.h:13
SbProjectMode
Project loading or saving mode that wraps the sb_t_project_mode enum
Definition: cs_project.h:18
SbDeviceType
Device type that wraps the sb_t_device_type enum
Definition: cs_common.h:181
SB Namespace
Definition: cs_common.h:3