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

Function main

examples/train_shape_predictor_ex.cpp:41–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39// ----------------------------------------------------------------------------------------
40
41int main(int argc, char** argv)
42{
43 try
44 {
45 // In this example we are going to train a shape_predictor based on the
46 // small faces dataset in the examples/faces directory. So the first
47 // thing we do is load that dataset. This means you need to supply the
48 // path to this faces folder as a command line argument so we will know
49 // where it is.
50 if (argc != 2)
51 {
52 cout << "Give the path to the examples/faces directory as the argument to this" << endl;
53 cout << "program. For example, if you are in the examples folder then execute " << endl;
54 cout << "this program by running: " << endl;
55 cout << " ./train_shape_predictor_ex faces" << endl;
56 cout << endl;
57 return 0;
58 }
59 const std::string faces_directory = argv[1];
60 // The faces directory contains a training dataset and a separate
61 // testing dataset. The training data consists of 4 images, each
62 // annotated with rectangles that bound each human face along with 68
63 // face landmarks on each face. The idea is to use this training data
64 // to learn to identify the position of landmarks on human faces in new
65 // images.
66 //
67 // Once you have trained a shape_predictor it is always important to
68 // test it on data it wasn't trained on. Therefore, we will also load
69 // a separate testing set of 5 images. Once we have a shape_predictor
70 // created from the training data we will see how well it works by
71 // running it on the testing images.
72 //
73 // So here we create the variables that will hold our dataset.
74 // images_train will hold the 4 training images and faces_train holds
75 // the locations and poses of each face in the training images. So for
76 // example, the image images_train[0] has the faces given by the
77 // full_object_detections in faces_train[0].
78 dlib::array<array2d<unsigned char> > images_train, images_test;
79 std::vector<std::vector<full_object_detection> > faces_train, faces_test;
80
81 // Now we load the data. These XML files list the images in each
82 // dataset and also contain the positions of the face boxes and
83 // landmarks (called parts in the XML file). Obviously you can use any
84 // kind of input format you like so long as you store the data into
85 // images_train and faces_train. But for convenience dlib comes with
86 // tools for creating and loading XML image dataset files. Here you see
87 // how to load the data. To create the XML files you can use the imglab
88 // tool which can be found in the tools/imglab folder. It is a simple
89 // graphical tool for labeling objects in images. To see how to use it
90 // read the tools/imglab/README.txt file.
91 load_image_dataset(images_train, faces_train, faces_directory+"/training_with_face_landmarks.xml");
92 load_image_dataset(images_test, faces_test, faces_directory+"/testing_with_face_landmarks.xml");
93
94 // Now make the object responsible for training the model.
95 shape_predictor_trainer trainer;
96 // This algorithm has a bunch of parameters you can mess with. The
97 // documentation for the shape_predictor_trainer explains all of them.
98 // You should also read Kazemi's paper which explains all the parameters

Callers

nothing calls this directly

Calls 11

load_image_datasetFunction · 0.85
test_shape_predictorFunction · 0.85
set_tree_depthMethod · 0.80
serializeFunction · 0.70
set_nuMethod · 0.45
set_num_threadsMethod · 0.45
be_verboseMethod · 0.45
trainMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected