faq.xml 16 KB
Newer Older
Davis King's avatar
Davis King committed
1
2
3
4
5
6
7
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>

<doc>
   <title>Frequently Asked Questions</title>

   <!-- ************************************************************************* -->
8
   <questions group="General">
9

Davis King's avatar
Davis King committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
      <question text="It doesn't work?">
         Do not post a question like "I'm using dlib, and it doesn't work?" or
         "I'm using the object detector and it doesn't work, what do I do?".
         If this is all you say then I have no idea what is wrong.  99% of the
         time it's some kind of user error.  1% of the time it's some problem
         in dlib.  But again, without more information it's impossible to know.
         So please don't post questions like this.  

         <p>
         If you think you found some kind of bug or problem in dlib then feel
         free to post on <a href="https://sourceforge.net/p/dclib/discussion">sourceforge</a> 
         or <a href="https://github.com/davisking/dlib/issues">github</a>.  
         But include the version of dlib you are using, what you
         are trying, what happened, what you expected to have happened instead, etc.
         </p>

         <p>
         On the other hand, if you haven't found a bug or problem in dlib, but
         instead are looking for machine learning/computer vision/programming
         consulting then you can still <a href="https://sourceforge.net/p/dclib/discussion">post your question on sourceforge</a>.  
         But be clear that this is what you are asking for.  Maybe someone will
         help you or you can find someone to pay money in exchange for a
         solution to your problem.  
         </p>
         
         <p>
         However, don't try to get someone to write your code for you by
         repeatedly asking a question like "ok, what do I type next to make a
         program that does X?".  I get this question all the time from people 
         who obviously don't know how to program.  If you are not familiar
         with C++ it's much better to learn it by 
         <a href="http://dlib.net/books.html">reading one of the excellent books on the topic</a>
         than by an infinite sequence of questions posted in the dlib forums.
         </p>

      </question>
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
      <question text="How can I use dlib in Visual Studio?">
         There are instructions on the <a href="compile.html">How to Compile</a> page.  
         If you do not understand the instructions in the "<b>Compiling on Windows Using Visual Studio</b>" section
         or are getting errors then follow the instructions in the "<b>Compiling on Any Operating System Using CMake</b>"
         section.  In particular, <a href="http://www.cmake.org/download/">install CMake</a> and then type 
         these exact commands from within the root of the dlib distribution:  
<code_box>
cd examples
mkdir build
cd build
del /F /S /Q *
cmake ..
cmake --build . --config Release
</code_box>
         That should compile the dlib examples in visual studio.  The output executables will appear in the Release folder.
         The <tt>del /F /S /Q *</tt> command is to make sure you clear out any extraneous files you might have placed in 
         the build folder and is not necessary if build begins empty.
      </question>

      <!-- ****************************************** -->

      <question text="Why is dlib slow?">
         Dlib isn't slow.  I get this question many times a week and 95% of the time it's from someone
         using Visual Studio who has compiled their program in Debug mode rather than the optimized
         Release mode.  So if you are using Visual Studio then realize that Visual Studio has these two modes.  
         The default is Debug.  The mode is selectable via a drop down:
         <p><img src="vs_mode_1.png"/></p>
         Debug mode disables compiler optimizations.  So the program will be very slow if you run it in Debug mode.
         So click the drop down,
         <p><img src="vs_mode_2.png"/></p>
         and select Release.
         <p><img src="vs_mode_3.png"/></p>
         Then when you compile the program it will appear in a folder named Release rather than in a folder named Debug.  

         <br/>
         <br/>
         Finally, you can enable either SSE4 or AVX instruction use.  These will make certain operations much faster (e.g. face detection).
         You do this using <a href="http://www.cmake.org/download/">CMake</a>'s cmake-gui tool.  For example, if you execute
         these commands you will get the cmake-gui screen:
<code_box>
cd examples
mkdir build
cd build
cmake .. 
cmake-gui .
</code_box>
         Which looks like this:
         <p><img src="vs-cmake-gui.png"/></p>
         Where you can select SSE4 or AVX instruction use.  Then you click configure and then generate. After that
         when you build your visual studio project some things will be faster.
         
         Finally, note that AVX is a little bit faster than SSE4 but if your computer is fairly old it might
         not support it.  In that case, either buy a new computer or use SSE4
         instructions. 
      </question>

      <!-- ****************************************** -->



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
      <question text="How can I cite dlib?">
         If you use dlib in your research then please use the following citation:
         <br/>
         <br/>
Davis E. King. <a href="http://jmlr.csail.mit.edu/papers/volume10/king09a/king09a.pdf">Dlib-ml: A Machine Learning Toolkit</a>. 
   <i>Journal of Machine Learning Research</i> 10, pp. 1755-1758, 2009
         <br/>
         <pre>

@Article{dlib09,
  author = {Davis E. King},
  title = {Dlib-ml: A Machine Learning Toolkit},
  journal = {Journal of Machine Learning Research},
  year = {2009},
  volume = {10},
  pages = {1755-1758},
}
         </pre>
      </question>

      <!-- ****************************************** -->



131
      <question text="Why isn't serialization working?">
Davis King's avatar
Davis King committed
132
         Here are the possibilities:
Davis King's avatar
Davis King committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
         <ul>
            <li>You are using a file stream and forgot to put it into binary mode.  
               You need to do something like this:
<code_box>
std::ifstream fin("myfile", std::ios::binary);
</code_box>
or
<code_box>
std::ofstream fout("myfile", std::ios::binary);
</code_box>

If you don't give <tt>std::ios::binary</tt> then the iostream will mess with the binary data and cause serialization
to not work right.  
            </li>

            <br/>
            <li>The iostream is in a bad state.  You can check the state by calling <tt>mystream.good()</tt>.
            If it returns false then the stream is in an error state such as end-of-file or maybe it failed
            to do the I/O.  Also note that if you close a file stream and reopen it you might have to call
            <tt>mystream.clear()</tt> to clear out the error flags.
            </li>
         </ul>

Davis King's avatar
Davis King committed
156
      </question>
Davis King's avatar
Davis King committed
157
      <!-- ****************************************** -->
Davis King's avatar
Davis King committed
158

159
      <question text="How do I set the size of a matrix at runtime?">
Davis King's avatar
Davis King committed
160
161
162
163
         Long answer, read the <a href="matrix_ex.cpp.html">matrix example program</a>.
         <br/><br/>
         Short answer, here are some examples:
<code_box>
Davis King's avatar
Davis King committed
164
165
matrix&lt;double&gt; mat;
mat.set_size(4,5);
166

Davis King's avatar
Davis King committed
167
168
matrix&lt;double,0,1&gt; column_vect;
column_vect.set_size(6);
Davis King's avatar
Davis King committed
169

Davis King's avatar
Davis King committed
170
matrix&lt;double,0,1&gt; column_vect2(6);  // give size to constructor
Davis King's avatar
Davis King committed
171

Davis King's avatar
Davis King committed
172
173
matrix&lt;double,1&gt; row_vect;
row_vect.set_size(5);
Davis King's avatar
Davis King committed
174
175
176
</code_box>

      </question>
Davis King's avatar
Davis King committed
177
      <!-- ****************************************** -->
Davis King's avatar
Davis King committed
178
179
180
181
182

      <question text="Where is the documentation for &lt;object/function&gt;?">
         If you can't find something then check the <a href="term_index.html">index</a>.
         <br/><br/>
         Also, the bulk of the documentation can be found by following the 
Davis King's avatar
Davis King committed
183
         <b><font style='font-size:1.3em' color='#0000FF'>Detailed Documentation</font></b> links.   
Davis King's avatar
Davis King committed
184
      </question>
185

Davis King's avatar
Davis King committed
186
187
188
189

      <!-- ****************************************** -->

      <question text="How does dlib interface with other libraries/tools?">
Davis King's avatar
Davis King committed
190
191
192
         There should never be anything in dlib that prevents you from using or 
         interacting with other libraries.  Moreover, there are some additional tools
         in dlib to make some interactions easier:  
Davis King's avatar
Davis King committed
193
194
195
196
197
198

         <ul>
            <li><b>BLAS and LAPACK libraries</b> are used by the <a href="linear_algebra.html#matrix">matrix</a>
            automatically if you <tt>#define</tt> DLIB_USE_BLAS and/or DLIB_USE_LAPACK and link against
            the appropriate library files.  Note that the CMakeLists.txt file that comes with dlib will
            do this for you automatically in many instances.</li><br/>
Davis King's avatar
Davis King committed
199

Davis King's avatar
Davis King committed
200
201
            <li><b>Armadillo and Eigen libraries</b> have matrix objects which can be converted into
            dlib matrix objects by calling dlib::mat() on them.</li><br/>
Davis King's avatar
Davis King committed
202

Davis King's avatar
Davis King committed
203
204
205
            <li><b>OpenCV</b> image objects can be converted into a form usable by dlib routines
            by using <a href="imaging.html#cv_image">cv_image</a>.  You can also convert from a
            dlib matrix or image to an OpenCV Mat using dlib::<a href="imaging.html#toMat">toMat</a>().</li><br/>
Davis King's avatar
Davis King committed
206

Davis King's avatar
Davis King committed
207
208
209
210
            <li><b>Google Protocol Buffers</b> can be serialized by the dlib 
            <a href="other.html#serialize">serialization</a> routines.  
            This means that, for example, you can pass protocol buffer objects through a 
            <a href="network.html#bridge">bridge</a>.
Davis King's avatar
Davis King committed
211
212
213
214
215
216
217
218
219
            </li><br/>

            <li><b>libpng and libjpeg</b> are used by <a
            href="imaging.html#load_image">load_image</a> whenever
            DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT are defined respectively.
            You must also tell your compiler to link against these libraries to
            use them. However, CMake will try to link against them
            automatically if they are installed.</li><br/>

Davis King's avatar
Davis King committed
220
221
            <!--<li><b>FFTW</b> is used by the fft() and ifft() routines if you #define DLIB_USE_FFTW and
            link to fftw3.  Otherwise dlib uses its own slower default implementation.  </li><br/> -->
Davis King's avatar
Davis King committed
222

Davis King's avatar
Davis King committed
223
224
225
226
            <li><b>SQLite</b> is used by the <a href="other.html#database">database</a> object.  In
            fact, it is just a wrapper around SQLite's C interface which simplifies its use (e.g. 
            makes resource management use RAII).</li>

Davis King's avatar
Davis King committed
227
228
229
         </ul>
      </question>

Davis King's avatar
Davis King committed
230
231
   </questions>

Davis King's avatar
Davis King committed
232
233
234



235
236
237
238
239
   <!-- ************************************************************************* -->

   <questions group="Machine Learning">

      <question text="Why is RVM training is really slow?">
Davis King's avatar
Davis King committed
240
241
242
243
244
245
246
247
248
249
250
         The optimization algorithm is somewhat unpredictable.  Sometimes it is fast and 
         sometimes it is slow.  What usually makes it really slow is if you use a radial basis
         kernel and you set the gamma parameter to something too large.  This causes the
         algorithm to start using a whole lot of relevance vectors (i.e. basis vectors) which
         then makes it slow.  The algorithm is only fast as long as the number of relevance vectors
         remains small but it is hard to know beforehand if that will be the case.  
         <p>
            You should try <a href="ml.html#krr_trainer">kernel ridge regression</a> instead since it
            also doesn't take any parameters but is always very fast.
         </p>

251
252
      </question>

Davis King's avatar
Davis King committed
253
254
      <!-- ****************************************** -->

255
      <question text="Why is cross_validate_trainer_threaded() crashing?">
Davis King's avatar
Davis King committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
         This function makes a copy of your training data for each thread.  So you are probably running out
         of memory.  To avoid this, use the <a href="algorithms.html#randomly_subsample">randomly_subsample</a> function
         to reduce the amount of data you are using or use fewer threads. 
         <p>
            For example, you could reduce the amount of data by saying this:
<code_box>
// reduce to only 1000 samples
cross_validate_trainer_threaded(trainer, 
                                randomly_subsample(samples, 1000), 
                                randomly_subsample(labels,  1000), 
                                4,   // num folds
                                4);  // num threads
</code_box>
         </p>
270
271
      </question>

Davis King's avatar
Davis King committed
272
273
      <!-- ****************************************** -->

274
      <question text="How can I define a custom kernel?">
Davis King's avatar
Davis King committed
275
         See the <a href="using_custom_kernels_ex.cpp.html">Using Custom Kernels</a> example program.
276
277
      </question>

Davis King's avatar
Davis King committed
278
279
      <!-- ****************************************** -->

280
281
282
      <question text="Can you give advice on feature generation/kernel selection?">
         <p>
            Picking the right kernel all comes down to understanding your data, and obviously this is 
Davis King's avatar
Davis King committed
283
            highly dependent on your problem.  
284
285
286
287
288
289
         </p>

         <p>
            One thing that's sometimes useful is to plot each feature against the target value.  You can get an idea of 
            what your overall feature space looks like and maybe tell if a linear kernel is the right solution.  But 
            this still hides important information from you.  For example, imagine you have two diagonal lines which 
Davis King's avatar
Davis King committed
290
            are very close together and are both the same length.  Suppose one line is of the +1 class and the other is the -1 
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
            class.  Each feature (the x or y coordinate values) by itself tells you almost nothing about which class 
            a point belongs to but together they tell you everything you need to know.  
         </p>

         <p>
            On the other hand, if you know something about the data you are working with then you can also try and 
            generate your own features.  So for example, if your data is a bunch of images and you know that one 
            of your classes contains a lot of lines then you can make a feature that attempts to measure the number 
            of lines in an image using a hough transform or sobel edge filter or whatever.  Generally, try and 
            think up features which should be highly correlated with your target value.  A good way to do this is 
            to try and actually hand code N solutions to the problem using whatever you know about your data or 
            domain.  If you do a good job then you will have N really great features and a linear or rbf kernel 
            will probably do very well when using them.
         </p>

         <p>
            Or you can just try a whole bunch of kernels, kernel parameters, and training algorithm options while 
            using cross validation.  I.e. when in doubt, use brute force :)   There is an example of that kind of 
            thing in the <a href="model_selection_ex.cpp.html">model selection</a> example program. 
         </p>
      </question>

Davis King's avatar
Davis King committed
313
314
      <!-- ****************************************** -->

315
      <question text="Why does my decision_function always give the same output?">
Davis King's avatar
Davis King committed
316
317
318
319
320
         This happens when you use the radial_basis_kernel and you set the gamma value to
         something highly inappropriate.  To understand what's happening lets imagine your
         data has just one feature and its value ranges from 0 to 7.  Then what you want is a 
         gamma value that gives nice Gaussian bumps like the one in this graph: <br/>

321
         <center><image src="rbf_normal.gif"/></center>
Davis King's avatar
Davis King committed
322
323
324
325

         <br/>
         However, if you make gamma really huge you will get this (it's zero everywhere except for one place):
         <br/>
326
         <center><image src="rbf_big_gamma.gif"/></center>
Davis King's avatar
Davis King committed
327
328
329
330

         <br/>
         Or if you make gamma really small then it will be 1.0 everywhere:
         <br/>
331
         <center><image src="rbf_small_gamma.gif"/></center>
Davis King's avatar
Davis King committed
332
333
334
335
336
337
338

         <p>
            So you need to pick the gamma value so that it is scaled reasonably to your data.  A <i><font color="red">good rule of
            thumb (i.e. not the optimal gamma, just a heuristic guess)</font></i> is the following:
         </p>
         <code_box>const double gamma = 1.0/compute_mean_squared_distance(randomly_subsample(samples, 2000));</code_box>
           
339
340
      </question>

Davis King's avatar
Davis King committed
341
342
      <!-- ****************************************** -->

343
   </questions>
Davis King's avatar
Davis King committed
344
345
346

   <!-- ************************************************************************* -->

347

Davis King's avatar
Davis King committed
348
</doc>