WIP: Serialization
This commit is contained in:
@@ -47,6 +47,14 @@ void DescriptorManager::Init() {
|
|||||||
}
|
}
|
||||||
fs::ifstream ifs;
|
fs::ifstream ifs;
|
||||||
fs::ofstream ofs;
|
fs::ofstream ofs;
|
||||||
|
{
|
||||||
|
ifstream f("features.map", ios::binary);
|
||||||
|
if (f.is_open()) {
|
||||||
|
ar::binary_iarchive bi(f);
|
||||||
|
bi >> features;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
numImages = std::count_if(
|
numImages = std::count_if(
|
||||||
fs::directory_iterator(img_path),
|
fs::directory_iterator(img_path),
|
||||||
fs::directory_iterator(),
|
fs::directory_iterator(),
|
||||||
@@ -62,6 +70,11 @@ void DescriptorManager::Init() {
|
|||||||
image->read(itr->path().string());
|
image->read(itr->path().string());
|
||||||
//foreach descriptor
|
//foreach descriptor
|
||||||
for (int i = 0; i < numDescriptors; i++) {
|
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
|
//folder to store descriptors; create if not exists
|
||||||
fs::path descriptorBase("meta" / descriptor_types[i]->ToPath());
|
fs::path descriptorBase("meta" / descriptor_types[i]->ToPath());
|
||||||
if (!fs::is_directory(descriptorBase))
|
if (!fs::is_directory(descriptorBase))
|
||||||
@@ -85,6 +98,21 @@ void DescriptorManager::Init() {
|
|||||||
ofs.close();
|
ofs.close();
|
||||||
}
|
}
|
||||||
features[i][image_name] = *b1;
|
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;
|
delete b1;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < numMutations; i++) {
|
for (int i = 0; i < numMutations; i++) {
|
||||||
@@ -95,12 +123,21 @@ void DescriptorManager::Init() {
|
|||||||
fs::path mutPath(mutationBase / itr->path().filename().generic_string());
|
fs::path mutPath(mutationBase / itr->path().filename().generic_string());
|
||||||
Image* mutated;
|
Image* mutated;
|
||||||
if (!fs::exists(mutPath)) { //only mutate if nothing on disk
|
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 = mutators[i]->getMutated(image);
|
||||||
mutated->write(mutPath.generic_string());
|
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 = new Image;
|
||||||
mutated->read(mutPath.generic_string());
|
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
|
//now calculate all the features for the mutated images as well
|
||||||
|
|||||||
@@ -8,6 +8,18 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/system/error_code.hpp>
|
#include <boost/system/error_code.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
//Boost serialization test:
|
||||||
|
#include <boost/archive/binary_oarchive.hpp>
|
||||||
|
#include <boost/archive/binary_iarchive.hpp>
|
||||||
|
#include <boost/serialization/map.hpp>
|
||||||
|
#include <boost/serialization/bitset.hpp>
|
||||||
|
#include <boost/serialization/string.hpp>
|
||||||
|
|
||||||
|
//YAS Serialization:
|
||||||
|
#include <yas/serialize.hpp>
|
||||||
|
#include <yas/std_types.hpp>
|
||||||
|
|
||||||
|
#include <chrono> //Debug, for measuring execution times
|
||||||
|
|
||||||
#include <Magick++.h>
|
#include <Magick++.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -15,11 +27,13 @@
|
|||||||
#include "Mutation.h"
|
#include "Mutation.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace chrono;
|
||||||
using namespace Magick;
|
using namespace Magick;
|
||||||
|
|
||||||
//ENUM_STRING(descriptorss, (totalColors)(averageColor)(numDescriptors))
|
//ENUM_STRING(descriptorss, (totalColors)(averageColor)(numDescriptors))
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
namespace ar = boost::archive;
|
||||||
|
|
||||||
//Manager class for descriptors.
|
//Manager class for descriptors.
|
||||||
//Contains functions to load, store, process
|
//Contains functions to load, store, process
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
CXX = g++
|
CXX = g++
|
||||||
CC = $(CXX)
|
CC = $(CXX)
|
||||||
CPPFLAGS = `Magick++-config --cppflags`
|
CPPFLAGS = `Magick++-config --cppflags`
|
||||||
BOOST_LIBS = -lboost_system -lboost_filesystem
|
BOOST_LIBS = -lboost_system -lboost_filesystem -lboost_serialization
|
||||||
LDFLAGS = `Magick++-config --ldflags` $(BOOST_LIBS)
|
LDFLAGS = `Magick++-config --ldflags` $(BOOST_LIBS)
|
||||||
SOURCES = DescriptorManager.cpp main.cpp
|
SOURCES = DescriptorManager.cpp main.cpp
|
||||||
OBJECTS = $(SOURCES:.cpp=.o)
|
OBJECTS = $(SOURCES:.cpp=.o)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ using namespace Magick;
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
string imagename = "im80.jpg";
|
string imagename = "spook.jpg";
|
||||||
int method = 6;
|
int method = 6;
|
||||||
int count = 1000;
|
int count = 1000;
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
@@ -39,24 +39,12 @@ int main(int argc, char **argv) {
|
|||||||
cout << "Continuing.." << endl;
|
cout << "Continuing.." << endl;
|
||||||
}
|
}
|
||||||
InitializeMagick(*argv);
|
InitializeMagick(*argv);
|
||||||
DescriptorManager* manager = new DescriptorManager("data");
|
DescriptorManager* manager = new DescriptorManager("test");
|
||||||
cout << "Intializing..." << endl;
|
//smanager->generatePreviews(imagename);
|
||||||
|
//cout << "Intializing..." << endl;
|
||||||
manager->Init();
|
manager->Init();
|
||||||
cout << "done!" << endl;
|
//cout << "done!" << endl;
|
||||||
manager->runExperiments();
|
manager->runExperiments();
|
||||||
//manager->rankImages(imagename, method);
|
|
||||||
//manager->rankMutations(imagename, method);
|
|
||||||
//manager->outputMap(method);
|
|
||||||
//manager->outputRank(imagename, method);
|
|
||||||
//cout << "Loading descriptiors..";
|
|
||||||
//manager->loadDescriptors();
|
|
||||||
//manager->createMutations();
|
|
||||||
//cout << "done?" << endl;
|
|
||||||
//manager->similarImages(imagename, method, count);
|
|
||||||
//manager->insertMutations(imagename, method);
|
|
||||||
//cout << "done!" << endl << "Calculating distances.." << endl;
|
|
||||||
//cout << "done!" << endl << "Outputting map.." << endl;
|
|
||||||
//manager->outputMap();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user