MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/learning_to_track_ex.cpp:252–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250// ----------------------------------------------------------------------------------------
251
252int main()
253{
254 initialize_object_properties();
255
256
257 // Get some training data. Here we sample 5 independent track histories. In a real
258 // world problem you would get this kind of data by, for example, collecting data from
259 // your sensor on 5 separate days where you did an independent collection each day.
260 // You can train a model with just one track history but the more you have the better.
261 std::vector<track_history> data;
262 data.push_back(make_random_tracking_data_for_training());
263 data.push_back(make_random_tracking_data_for_training());
264 data.push_back(make_random_tracking_data_for_training());
265 data.push_back(make_random_tracking_data_for_training());
266 data.push_back(make_random_tracking_data_for_training());
267
268
269 structural_track_association_trainer trainer;
270 // Note that the machine learning tools have a parameter. This is the usual SVM C
271 // parameter that controls the trade-off between trying to fit the training data or
272 // producing a "simpler" solution. You need to try a few different values of this
273 // parameter to find out what setting works best for your problem (try values in the
274 // range 0.001 to 1000000).
275 trainer.set_c(100);
276 // Now do the training.
277 track_association_function<detection> assoc = trainer.train(data);
278
279 // We can test the accuracy of the learned association function on some track history
280 // data. Here we test it on the data we trained on. It outputs a single number that
281 // measures the fraction of detections which were correctly associated to their tracks.
282 // So a value of 1 indicates perfect tracking and a value of 0 indicates totally wrong
283 // tracking.
284 cout << "Association accuracy on training data: "<< test_track_association_function(assoc, data) << endl;
285 // It's very important to test the output of a machine learning method on data it
286 // wasn't trained on. You can do that by calling test_track_association_function() on
287 // held out data. You can also use cross-validation like so:
288 cout << "Association accuracy from 5-fold CV: "<< cross_validate_track_association_trainer(trainer, data, 5) << endl;
289 // Unsurprisingly, the testing functions show that the assoc function we learned
290 // perfectly associates all detections to tracks in this easy data.
291
292
293
294
295 // OK. So how do you use this assoc thing? Let's use it to do some tracking!
296
297 // tracks contains all our current tracks. Initially it is empty.
298 std::vector<track> tracks;
299 cout << "number of tracks: "<< tracks.size() << endl;
300
301 // Sample detections from 3 objects.
302 std::vector<detection> dets = make_random_detections(3);
303 // Calling assoc(), the function we just learned, performs the detection to track
304 // association. It will also call each track's update_track() function with the
305 // associated detection. For tracks that don't get a detection, it calls
306 // propagate_track().
307 assoc(tracks, dets);
308 // Now there are 3 things in tracks.
309 cout << "number of tracks: "<< tracks.size() << endl;

Callers

nothing calls this directly

Calls 11

make_random_detectionsFunction · 0.70
serializeFunction · 0.70
deserializeFunction · 0.70
push_backMethod · 0.45
set_cMethod · 0.45
trainMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected