Refactor caching
This commit is contained in:
+51
-22
@@ -47,13 +47,7 @@ void DescriptorManager::Init() {
|
||||
}
|
||||
fs::ifstream ifs;
|
||||
fs::ofstream ofs;
|
||||
{
|
||||
ifstream f("features.map", ios::binary);
|
||||
if (f.is_open()) {
|
||||
ar::binary_iarchive bi(f);
|
||||
bi >> features;
|
||||
}
|
||||
}
|
||||
LoadFeatures();
|
||||
|
||||
numImages = std::count_if(
|
||||
fs::directory_iterator(img_path),
|
||||
@@ -98,21 +92,7 @@ void DescriptorManager::Init() {
|
||||
ofs.close();
|
||||
}
|
||||
features[i][image_name] = *b1;
|
||||
{
|
||||
ofstream f("features.map", ios::binary);
|
||||
//ofstream feature_cache_backup("features.map.bak", ios::binary);
|
||||
//feature_cache_backup << feature_cache.rdbuf();
|
||||
ar::binary_oarchive oa(f);
|
||||
oa << features;
|
||||
}
|
||||
|
||||
{
|
||||
yas::file_ostream os("features.yas", yas::file_mode::file_trunc);
|
||||
//const std::size_t flg = yas::binary|yas::file;
|
||||
yas::binary_oarchive<yas::file_ostream, yas::file|yas::binary> oa(os);
|
||||
oa & features;
|
||||
//yas::save<yas::file|yas::binary>(image_name, features);
|
||||
}
|
||||
SaveFeatures();
|
||||
delete b1;
|
||||
}
|
||||
for (int i = 0; i < numMutations; i++) {
|
||||
@@ -120,6 +100,12 @@ void DescriptorManager::Init() {
|
||||
fs::path mutationBase(img_path / mutators[i]->ToPath());
|
||||
if (!fs::is_directory(mutationBase))
|
||||
fs::create_directory(mutationBase);
|
||||
bool missing = false;
|
||||
for (int j = 0; j < numDescriptors; j++) {
|
||||
if (mutatedFeatures[j][i].count(image_name) <= 0) {
|
||||
missing = true;
|
||||
}
|
||||
}
|
||||
fs::path mutPath(mutationBase / itr->path().filename().generic_string());
|
||||
Image* mutated;
|
||||
if (!fs::exists(mutPath)) { //only mutate if nothing on disk
|
||||
@@ -179,6 +165,49 @@ void DescriptorManager::Init() {
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
||||
//Saves feature map to disk.
|
||||
//Makes it so that it can reload easily
|
||||
void DescriptorManager::SaveFeatures() {
|
||||
{ //Boost serialization
|
||||
ofstream f("features.map", ios::binary);
|
||||
//ofstream feature_cache_backup("features.map.bak", ios::binary);
|
||||
//feature_cache_backup << feature_cache.rdbuf();
|
||||
ar::binary_oarchive oa(f);
|
||||
oa << features;
|
||||
|
||||
ofstream fm("mutated_features.map", ios::binary);
|
||||
ar::binary_oarchive oam(fm);
|
||||
oam << mutatedFeatures;
|
||||
}
|
||||
{ //YAS serialization
|
||||
yas::file_ostream os("features.yas", yas::file_mode::file_trunc);
|
||||
//const std::size_t flg = yas::binary|yas::file;
|
||||
yas::binary_oarchive<yas::file_ostream, yas::file|yas::binary> oa(os);
|
||||
oa & features;
|
||||
//yas::save<yas::file|yas::binary>(image_name, features);
|
||||
}
|
||||
}
|
||||
|
||||
//Loads saved feature maps from disk.
|
||||
void DescriptorManager::LoadFeatures() {
|
||||
{ //Boost
|
||||
ifstream f("features.map", ios::binary);
|
||||
if (f.is_open()) {
|
||||
ar::binary_iarchive bi(f);
|
||||
bi >> features;
|
||||
}
|
||||
ifstream fm("mutated_features.map", ios::binary);
|
||||
if (fm.is_open()) {
|
||||
ar::binary_iarchive bim(fm);
|
||||
bim >> mutatedFeatures;
|
||||
}
|
||||
}
|
||||
{ //YAS
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Sorts all base (unmutated) images in order of distance from the given image
|
||||
//After this function the distances array will be filled
|
||||
void DescriptorManager::rankImages(string image_name, int method) {
|
||||
|
||||
Reference in New Issue
Block a user