Added some stuff to a few of the examples regarding saving things to

disk with serialize().

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402622
This commit is contained in:
Davis King 2008-10-31 18:12:18 +00:00
parent a03e9b2e1a
commit 93542b8869
4 changed files with 64 additions and 0 deletions

View File

@ -71,6 +71,27 @@ int main()
// The first column is the true value of the sinc function and the second
// column is the output from the krls estimate.
// 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();
// now lets open that file back up and load the krls object it contains
ifstream fin("saved_krls_object.dat",ios::binary);
deserialize(test, fin);
// 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);
}

View File

@ -192,5 +192,17 @@ int main()
cout << "This -1 example should have low probability. It's probability is: " << learned_pfunct(sample) << endl;
// 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();
// now lets open that file back up and load the function object it contains
ifstream fin("saved_function.dat",ios::binary);
deserialize(learned_pfunct, fin);
}

View File

@ -70,6 +70,19 @@ int main()
// The first column is the true value of the sinc function and the second
// column is the output from the rvm estimate.
// 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();
// now lets open that file back up and load the function object it contains
ifstream fin("saved_function.dat",ios::binary);
deserialize(test, fin);
}

View File

@ -199,6 +199,24 @@ 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();
// now lets open that file back up and load the function object it contains
ifstream fin("saved_function.dat",ios::binary);
deserialize(learned_pfunct, fin);
// 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 piece of C++ code
// that is able to fully reproduce the file's contents in the form of a std::string object.
// So you can use that along with the std::istringstream to save learned decision functions
// inside your actual C++ code files if you want.
// Lastly, note that the decision functions we trained above involved well over 100
// support vectors. Support vector machines in general tend to find decision functions