Made the examples use the new simplified file serialization API.

pull/2/head
Davis King 11 years ago
parent eb2806f348
commit c6d778eaf9

@ -195,13 +195,10 @@ int main()
// Finally, the assigner can be serialized to disk just like most dlib objects.
ofstream fout("assigner.dat", ios::binary);
serialize(assigner, fout);
fout.close();
serialize("assigner.dat") << assigner;
// recall from disk
ifstream fin("assigner.dat", ios::binary);
deserialize(assigner, fin);
deserialize("assigner.dat") >> assigner;
}
catch (std::exception& e)
{

@ -208,15 +208,12 @@ int main()
decision_function<radial_basis_kernel<sample_type> > // This is the output of the rbf_trainer
> df2, df3;
df2 = df;
ofstream fout("df.dat", ios::binary);
serialize(df2, fout);
fout.close();
// save to a file called df.dat
serialize("df.dat") << df2;
// load the function back in from disk and store it in df3.
ifstream fin("df.dat", ios::binary);
deserialize(df3, fin);
deserialize("df.dat") >> df3;
// Test df3 to see that this worked.

@ -180,14 +180,11 @@ int main(int argc, char** argv)
// Like everything in dlib, you can save your detector to disk using the
// serialize() function.
ofstream fout("face_detector.svm", ios::binary);
serialize(detector, fout);
fout.close();
serialize("face_detector.svm") << detector;
// Then you can recall it using the deserialize() function.
ifstream fin("face_detector.svm", ios::binary);
object_detector<image_scanner_type> detector2;
deserialize(detector2, fin);
deserialize("face_detector.svm") >> detector2;

@ -78,21 +78,17 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the test object to disk and recall it later like so:
ofstream fout("saved_krls_object.dat",ios::binary);
serialize(test,fout);
fout.close();
serialize("saved_krls_object.dat") << test;
// Now let's open that file back up and load the krls object it contains.
ifstream fin("saved_krls_object.dat",ios::binary);
deserialize(test, fin);
deserialize("saved_krls_object.dat") >> test;
// If you don't want to save the whole krls object (it might be a bit large)
// you can save just the decision function it has learned so far. You can get
// the decision function out of it by calling test.get_decision_function() and
// then you can serialize that object instead. E.g.
decision_function<kernel_type> funct = test.get_decision_function();
fout.open("saved_krls_function.dat",ios::binary);
serialize(funct, fout);
serialize("saved_krls_function.dat") << funct;
}

@ -196,14 +196,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the learned_pfunct object to disk and recall it later like so:
ofstream fout("saved_function.dat",ios::binary);
serialize(learned_pfunct,fout);
fout.close();
serialize("saved_function.dat") << learned_pfunct;
// Now let's open that file back up and load the function object it contains.
ifstream fin("saved_function.dat",ios::binary);
deserialize(learned_pfunct, fin);
deserialize("saved_function.dat") >> learned_pfunct;
}

@ -94,14 +94,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the test object to disk and recall it later like so:
ofstream fout("saved_function.dat",ios::binary);
serialize(test,fout);
fout.close();
serialize("saved_function.dat") << test;
// Now let's open that file back up and load the function object it contains.
ifstream fin("saved_function.dat",ios::binary);
deserialize(test, fin);
deserialize("saved_function.dat") >> test;
}

@ -344,13 +344,10 @@ int main()
// Finally, you can save your track_association_function to disk like so:
ofstream fout("track_assoc.svm", ios::binary);
serialize(assoc, fout);
fout.close();
serialize("track_assoc.svm") << assoc;
// And recall it from disk later like so:
ifstream fin("track_assoc.svm", ios::binary);
deserialize(assoc, fin);
deserialize("track_assoc.svm") >> assoc;
}
// ----------------------------------------------------------------------------------------

@ -138,13 +138,10 @@ int main()
// Put df into df2 and then save df2 to disk. Note that we could have also said
// df2 = trainer.train(samples, labels); But doing it this way avoids retraining.
df2 = df;
ofstream fout("df.dat", ios::binary);
serialize(df2, fout);
fout.close();
serialize("df.dat") << df2;
// load the function back in from disk and store it in df3.
ifstream fin("df.dat", ios::binary);
deserialize(df3, fin);
deserialize("df.dat") >> df3;
// Test df3 to see that this worked.

@ -247,13 +247,10 @@ int main()
// Finally, note that the detector can be serialized to disk just like other dlib objects.
ofstream fout("object_detector.dat", ios::binary);
serialize(detector, fout);
fout.close();
serialize("object_detector.dat") << detector;
// Recall from disk.
ifstream fin("object_detector.dat", ios::binary);
deserialize(detector, fin);
deserialize("object_detector.dat") >> detector;
}
catch (exception& e)
{

@ -208,14 +208,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the learned_pfunct object to disk and recall it later like so:
ofstream fout("saved_function.dat",ios::binary);
serialize(learned_pfunct,fout);
fout.close();
serialize("saved_function.dat") << learned_pfunct;
// Now let's open that file back up and load the function object it contains.
ifstream fin("saved_function.dat",ios::binary);
deserialize(learned_pfunct, fin);
deserialize("saved_function.dat") >> learned_pfunct;
}

@ -91,14 +91,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is serializable.
// So for example, you can save the test object to disk and recall it later like so:
ofstream fout("saved_function.dat",ios::binary);
serialize(test,fout);
fout.close();
serialize("saved_function.dat") << test;
// Now let's open that file back up and load the function object it contains.
ifstream fin("saved_function.dat",ios::binary);
deserialize(test, fin);
deserialize("saved_function.dat") >> test;
}

@ -292,13 +292,10 @@ int main()
// Finally, the labeler can be serialized to disk just like most dlib objects.
ofstream fout("labeler.dat", ios::binary);
serialize(labeler, fout);
fout.close();
serialize("labeler.dat") << labeler;
// recall from disk
ifstream fin("labeler.dat", ios::binary);
deserialize(labeler, fin);
deserialize("labeler.dat") >> labeler;
}
// ----------------------------------------------------------------------------------------

@ -228,13 +228,10 @@ int main()
// Finally, the segmenter can be serialized to disk just like most dlib objects.
ofstream fout("segmenter.dat", ios::binary);
serialize(segmenter, fout);
fout.close();
serialize("segmenter.dat") << segmenter;
// recall from disk
ifstream fin("segmenter.dat", ios::binary);
deserialize(segmenter, fin);
deserialize("segmenter.dat") >> segmenter;
}
// ----------------------------------------------------------------------------------------

@ -210,13 +210,10 @@ int main()
// Another thing that is worth knowing is that just about everything in dlib is
// serializable. So for example, you can save the learned_pfunct object to disk and
// recall it later like so:
ofstream fout("saved_function.dat",ios::binary);
serialize(learned_pfunct,fout);
fout.close();
serialize("saved_function.dat") << learned_pfunct;
// Now let's open that file back up and load the function object it contains.
ifstream fin("saved_function.dat",ios::binary);
deserialize(learned_pfunct, fin);
deserialize("saved_function.dat") >> learned_pfunct;
// Note that there is also an example program that comes with dlib called the
// file_to_code_ex.cpp example. It is a simple program that takes a file and outputs a

@ -291,9 +291,7 @@ int main(int argc, char** argv)
object_detector<image_scanner_type> detector = trainer.train(images, object_locations, ignore);
cout << "Saving trained detector to object_detector.svm" << endl;
ofstream fout("object_detector.svm", ios::binary);
serialize(detector, fout);
fout.close();
serialize("object_detector.svm") << detector;
cout << "Testing detector on training data..." << endl;
cout << "Test detector (precision,recall,AP): " << test_object_detection_function(detector, images, object_locations) << endl;

Loading…
Cancel
Save