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

Function main

examples/dnn_inception_ex.cpp:64–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 >>>>>>>>;
63
64int main(int argc, char** argv) try
65{
66 // This example is going to run on the MNIST dataset.
67 if (argc != 2)
68 {
69 cout << "This example needs the MNIST dataset to run!" << endl;
70 cout << "You can get MNIST from http://yann.lecun.com/exdb/mnist/" << endl;
71 cout << "Download the 4 files that comprise the dataset, decompress them, and" << endl;
72 cout << "put them in a folder. Then give that folder as input to this program." << endl;
73 return 1;
74 }
75
76
77 std::vector<matrix<unsigned char>> training_images;
78 std::vector<unsigned long> training_labels;
79 std::vector<matrix<unsigned char>> testing_images;
80 std::vector<unsigned long> testing_labels;
81 load_mnist_dataset(argv[1], training_images, training_labels, testing_images, testing_labels);
82
83
84 // Make an instance of our inception network.
85 net_type net;
86 cout << "The net has " << net.num_layers << " layers in it." << endl;
87 cout << net << endl;
88
89
90 cout << "Training NN..." << endl;
91 dnn_trainer<net_type> trainer(net);
92 trainer.set_learning_rate(0.01);
93 trainer.set_min_learning_rate(0.00001);
94 trainer.set_mini_batch_size(128);
95 trainer.be_verbose();
96 trainer.set_synchronization_file("inception_sync", std::chrono::seconds(20));
97 // Train the network. This might take a few minutes...
98 trainer.train(training_images, training_labels);
99
100 // At this point our net object should have learned how to classify MNIST images. But
101 // before we try it out let's save it to disk. Note that, since the trainer has been
102 // running images through the network, net will have a bunch of state in it related to
103 // the last batch of images it processed (e.g. outputs from each layer). Since we
104 // don't care about saving that kind of stuff to disk we can tell the network to forget
105 // about that kind of transient data so that our file will be smaller. We do this by
106 // "cleaning" the network before saving it.
107 net.clean();
108 serialize("mnist_network_inception.dat") << net;
109 // Now if we later wanted to recall the network from disk we can simply say:
110 // deserialize("mnist_network_inception.dat") >> net;
111
112
113 // Now let's run the training images through the network. This statement runs all the
114 // images through it and asks the loss layer to convert the network's raw output into
115 // labels. In our case, these labels are the numbers between 0 and 9.
116 std::vector<unsigned long> predicted_labels = net(training_images);
117 int num_right = 0;
118 int num_wrong = 0;
119 // And then let's see if it classified them correctly.
120 for (size_t i = 0; i < training_images.size(); ++i)
121 {

Callers

nothing calls this directly

Calls 11

load_mnist_datasetFunction · 0.85
set_learning_rateMethod · 0.80
set_min_learning_rateMethod · 0.80
set_mini_batch_sizeMethod · 0.80
serializeFunction · 0.70
be_verboseMethod · 0.45
trainMethod · 0.45
cleanMethod · 0.45
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected