WIP: Serialization
This commit is contained in:
+38
-1
@@ -47,6 +47,14 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
numImages = std::count_if(
|
||||
fs::directory_iterator(img_path),
|
||||
fs::directory_iterator(),
|
||||
@@ -62,6 +70,11 @@ void DescriptorManager::Init() {
|
||||
image->read(itr->path().string());
|
||||
//foreach descriptor
|
||||
for (int i = 0; i < numDescriptors; i++) {
|
||||
//First check if we already have this information from the loaded cache
|
||||
if (features[i].count(image_name) > 0) {
|
||||
cout << "We already have feature for " << image_name << endl;
|
||||
continue;
|
||||
}
|
||||
//folder to store descriptors; create if not exists
|
||||
fs::path descriptorBase("meta" / descriptor_types[i]->ToPath());
|
||||
if (!fs::is_directory(descriptorBase))
|
||||
@@ -85,6 +98,21 @@ 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);
|
||||
}
|
||||
delete b1;
|
||||
}
|
||||
for (int i = 0; i < numMutations; i++) {
|
||||
@@ -95,12 +123,21 @@ void DescriptorManager::Init() {
|
||||
fs::path mutPath(mutationBase / itr->path().filename().generic_string());
|
||||
Image* mutated;
|
||||
if (!fs::exists(mutPath)) { //only mutate if nothing on disk
|
||||
//Measured: about 10ms
|
||||
auto start = high_resolution_clock::now();
|
||||
mutated = mutators[i]->getMutated(image);
|
||||
mutated->write(mutPath.generic_string());
|
||||
auto duration = duration_cast<microseconds>(high_resolution_clock::now() - start);
|
||||
cout << "Calculating mutation " << mutators[i]->ToString() << " took " << duration.count() << "μs." << endl;
|
||||
|
||||
}
|
||||
else {
|
||||
else {
|
||||
//Measured: about 4ms
|
||||
auto start = high_resolution_clock::now();
|
||||
mutated = new Image;
|
||||
mutated->read(mutPath.generic_string());
|
||||
auto duration = duration_cast<microseconds>(high_resolution_clock::now() - start);
|
||||
cout << "Loading mutation " << mutators[i]->ToString() << " took " << duration.count() << "μs." << endl;
|
||||
}
|
||||
|
||||
//now calculate all the features for the mutated images as well
|
||||
|
||||
Reference in New Issue
Block a user