mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Made trainer disk synchronization more reliable and efficient.
This commit is contained in:
parent
08f965a32b
commit
4b2178c6e6
@ -281,21 +281,11 @@ namespace dlib
|
|||||||
sync_filename = filename;
|
sync_filename = filename;
|
||||||
time_between_syncs = time_between_syncs_;
|
time_between_syncs = time_between_syncs_;
|
||||||
|
|
||||||
// check if the sync file already exists, if it does we should load it. We
|
// check if the sync file already exists, if it does we should load it.
|
||||||
// first check for a .tmp version since that would be the newest if it existed.
|
|
||||||
// If it doesn't exist we check the canonical sync file.
|
|
||||||
std::ifstream fin(filename+".tmp", std::ios::binary);
|
|
||||||
if (fin)
|
|
||||||
{
|
|
||||||
deserialize(*this, fin);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::ifstream fin(filename, std::ios::binary);
|
std::ifstream fin(filename, std::ios::binary);
|
||||||
if (fin)
|
if (fin)
|
||||||
deserialize(*this, fin);
|
deserialize(*this, fin);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
double get_average_loss (
|
double get_average_loss (
|
||||||
) const
|
) const
|
||||||
@ -521,6 +511,9 @@ namespace dlib
|
|||||||
// save our state to a temp file
|
// save our state to a temp file
|
||||||
std::string tempfile = sync_filename + ".tmp";
|
std::string tempfile = sync_filename + ".tmp";
|
||||||
std::ofstream fout(tempfile, std::ios::binary);
|
std::ofstream fout(tempfile, std::ios::binary);
|
||||||
|
// compact network before saving to disk.
|
||||||
|
wait_for_thread_to_pause();
|
||||||
|
this->net.clean();
|
||||||
serialize(*this, fout);
|
serialize(*this, fout);
|
||||||
fout.close();
|
fout.close();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user