summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/svm/structural_track_association_trainer_abstract.h
blob: e78fadef7183ef2dd1e97634d160cd8ae18a37cf (plain)
1
2
3
4
5
6
7
8
9
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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// Copyright (C) 2014  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#undef DLIB_STRUCTURAL_TRACK_ASSOCIATION_TRAnER_ABSTRACT_Hh_
#ifdef DLIB_STRUCTURAL_TRACK_ASSOCIATION_TRAnER_ABSTRACT_Hh_

#include "track_association_function_abstract.h"
#include "structural_assignment_trainer_abstract.h"

namespace dlib
{

// ----------------------------------------------------------------------------------------

    class structural_track_association_trainer
    {
        /*!
            WHAT THIS OBJECT REPRESENTS
                This object is a tool for learning to solve a track association problem.  That 
                is, it takes in a set of training data and outputs a track_association_function 
                you can use to do detection to track association.  The training data takes the
                form of a set or sets of "track histories".  Each track history is a
                std::vector where each element contains all the detections from a single time
                step.  Moreover, each detection has a label that uniquely identifies which
                object (e.g. person or whatever) the detection really corresponds to.  That is,
                the labels indicate the correct detection to track associations.  The goal of
                this object is then to produce a track_association_function that can perform a
                correct detection to track association at each time step.
        !*/

    public:

        structural_track_association_trainer (
        );  
        /*!
            ensures
                - #get_c() == 100
                - this object isn't verbose
                - #get_epsilon() == 0.001
                - #get_num_threads() == 2
                - #get_max_cache_size() == 5
                - #learns_nonnegative_weights() == false
                - #get_loss_per_track_break() == 1
                - #get_loss_per_false_association() == 1
        !*/

        void set_num_threads (
            unsigned long num
        );
        /*!
            ensures
                - #get_num_threads() == num
        !*/

        unsigned long get_num_threads (
        ) const;
        /*!
            ensures
                - returns the number of threads used during training.  You should 
                  usually set this equal to the number of processing cores on your
                  machine.
        !*/

        void set_epsilon (
            double eps
        );
        /*!
            requires
                - eps > 0
            ensures
                - #get_epsilon() == eps
        !*/

        double get_epsilon (
        ) const; 
        /*!
            ensures
                - returns the error epsilon that determines when training should stop.
                  Smaller values may result in a more accurate solution but take longer to
                  train.  You can think of this epsilon value as saying "solve the
                  optimization problem until the average number of association mistakes per
                  time step is within epsilon of its optimal value".
        !*/

        void set_max_cache_size (
            unsigned long max_size
        );
        /*!
            ensures
                - #get_max_cache_size() == max_size
        !*/

        unsigned long get_max_cache_size (
        ) const;
        /*!
            ensures
                - During training, this object basically runs the track_association_function on 
                  each training sample, over and over.  To speed this up, it is possible to 
                  cache the results of these invocations.  This function returns the number 
                  of cache elements per training sample kept in the cache.  Note that a value 
                  of 0 means caching is not used at all.  
        !*/

        void be_verbose (
        );
        /*!
            ensures
                - This object will print status messages to standard out so that a user can
                  observe the progress of the algorithm.
        !*/

        void be_quiet (
        );
        /*!
            ensures
                - this object will not print anything to standard out
        !*/

        void set_loss_per_false_association (
            double loss
        );
        /*!
            requires
                - loss > 0
            ensures
                - #get_loss_per_false_association() == loss
        !*/

        double get_loss_per_false_association (
        ) const;
        /*!
            ensures
                - returns the amount of loss experienced for assigning a detection to the
                  wrong track.  If you care more about avoiding false associations than
                  avoiding track breaks then you can increase this value.
        !*/

        void set_loss_per_track_break (
            double loss
        );
        /*!
            requires
                - loss > 0
            ensures
                - #get_loss_per_track_break() == loss
        !*/

        double get_loss_per_track_break (
        ) const;
        /*!
            ensures
                - returns the amount of loss experienced for incorrectly assigning a
                  detection to a new track instead of assigning it to its existing track.
                  If you care more about avoiding track breaks than avoiding things like
                  track swaps then you can increase this value.
        !*/

        void set_oca (
            const oca& item
        );
        /*!
            ensures
                - #get_oca() == item 
        !*/

        const oca get_oca (
        ) const;
        /*!
            ensures
                - Internally this object treats track association learning as a structural
                  SVM problem.  This routine returns a copy of the optimizer used to solve
                  the structural SVM problem.  
        !*/

        void set_c (
            double C
        );
        /*!
            ensures
                - returns the SVM regularization parameter.  It is the parameter that
                  determines the trade-off between trying to fit the training data (i.e.
                  minimize the loss) or allowing more errors but hopefully improving the
                  generalization of the resulting track_association_function.  Larger
                  values encourage exact fitting while smaller values of C may encourage
                  better generalization. 
        !*/

        double get_c (
        ) const;
        /*!
            requires
                - C > 0
            ensures
                - #get_c() = C
        !*/

        bool learns_nonnegative_weights (
        ) const; 
        /*!
            ensures
                - Ultimately, the output of training is a parameter vector that defines the
                  behavior of the track_association_function.  If
                  learns_nonnegative_weights() == true then the resulting learned parameter
                  vector will always have non-negative entries.
        !*/
       
        void set_learns_nonnegative_weights (
            bool value
        );
        /*!
            ensures
                - #learns_nonnegative_weights() == value
        !*/

        template <
            typename detection_type,
            typename label_type
            >
        const track_association_function<detection_type> train (  
            const std::vector<std::vector<labeled_detection<detection_type,label_type> > >& sample
        ) const;
        /*!
            requires
                - is_track_association_problem(sample) == true
            ensures
                - This function attempts to learn to do track association from the given
                  training data.  Note that we interpret sample as a single track history such
                  that sample[0] are all detections from the first time step, then sample[1]
                  are detections from the second time step, and so on.  
                - returns a function F such that:
                    - Executing F(tracks, detections) will try to correctly associate the
                      contents of detections to the contents of tracks and perform track
                      updating and creation.
                    - if (learns_nonnegative_weights() == true) then
                        - min(F.get_assignment_function().get_weights()) >= 0
        !*/

        template <
            typename detection_type,
            typename label_type
            >
        const track_association_function<detection_type> train (  
            const std::vector<std::vector<std::vector<labeled_detection<detection_type,label_type> > > >& sample
        ) const;
        /*!
            requires
                - is_track_association_problem(samples) == true
            ensures
                - This function attempts to learn to do track association from the given
                  training data.  In this case, we take a set of track histories as
                  training data instead of just one track history as with the above train()
                  method.
                - returns a function F such that:
                    - Executing F(tracks, detections) will try to correctly associate the
                      contents of detections to the contents of tracks and perform track
                      updating and creation.
                    - if (learns_nonnegative_weights() == true) then
                        - min(F.get_assignment_function().get_weights()) >= 0
        !*/

    };

// ----------------------------------------------------------------------------------------

}

#endif // DLIB_STRUCTURAL_TRACK_ASSOCIATION_TRAnER_ABSTRACT_Hh_