WIP: vector migration
This commit is contained in:
+43
-28
@@ -76,9 +76,9 @@ Image* DescriptorManager::GetMutated(Image* image, string image_name, int method
|
|||||||
void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
||||||
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
|
//First check if we already have this information from the loaded cache
|
||||||
if (features[i].count(image_name) > 0) {
|
/*if (features[i].count(image_name) > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}*/
|
||||||
if(!current_image) current_image = new Image(image_path);
|
if(!current_image) current_image = new Image(image_path);
|
||||||
fs::path featurePath("meta" / descriptor_types[i]->ToPath() / image_name);
|
fs::path featurePath("meta" / descriptor_types[i]->ToPath() / image_name);
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
|||||||
ofs.write(reinterpret_cast<const char*>(&b1), sizeof(b1));
|
ofs.write(reinterpret_cast<const char*>(&b1), sizeof(b1));
|
||||||
ofs.close();
|
ofs.close();
|
||||||
}
|
}
|
||||||
|
features_vector[i].push_back(pair<string, uint64_t>(image_name, b1));
|
||||||
features[i][image_name] = b1;
|
features[i][image_name] = b1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,9 +103,9 @@ void DescriptorManager::LoadFeatures(string image_path, string image_name) {
|
|||||||
void DescriptorManager::LoadMutationFeatures(string image_path, string image_name, int mutation) {
|
void DescriptorManager::LoadMutationFeatures(string image_path, string image_name, int mutation) {
|
||||||
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
|
//First check if we already have this information from the loaded cache
|
||||||
if (mutatedFeatures[i][mutation].count(image_name) > 0) {
|
/*if (mutatedFeatures[i][mutation].count(image_name) > 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}*/
|
||||||
if (!current_image) current_image->read(image_path);
|
if (!current_image) current_image->read(image_path);
|
||||||
Image* image = GetMutated(current_image, image_name, i);
|
Image* image = GetMutated(current_image, image_name, i);
|
||||||
fs::path featurePath("meta" / descriptor_types[i]->ToPath() / mutators[mutation]->ToPath() / image_name);
|
fs::path featurePath("meta" / descriptor_types[i]->ToPath() / mutators[mutation]->ToPath() / image_name);
|
||||||
@@ -122,6 +122,7 @@ void DescriptorManager::LoadMutationFeatures(string image_path, string image_nam
|
|||||||
ofs.write(reinterpret_cast<const char*>(&b1), sizeof(b1));
|
ofs.write(reinterpret_cast<const char*>(&b1), sizeof(b1));
|
||||||
ofs.close();
|
ofs.close();
|
||||||
}
|
}
|
||||||
|
mutatedFeatures_vector[i][mutation].push_back(pair<string, uint64_t>(image_name, b1));
|
||||||
mutatedFeatures[i][mutation][image_name] = b1;
|
mutatedFeatures[i][mutation][image_name] = b1;
|
||||||
delete image;
|
delete image;
|
||||||
}
|
}
|
||||||
@@ -130,12 +131,22 @@ void DescriptorManager::LoadMutationFeatures(string image_path, string image_nam
|
|||||||
//Calculates all features, mutations and features of mutations.
|
//Calculates all features, mutations and features of mutations.
|
||||||
//Do this before anything else.
|
//Do this before anything else.
|
||||||
void DescriptorManager::Init() {
|
void DescriptorManager::Init() {
|
||||||
|
high_resolution_clock::time_point t1 = high_resolution_clock::now();
|
||||||
LoadFromDisk();
|
LoadFromDisk();
|
||||||
|
CompareFeatures();
|
||||||
|
CopyFeatures();
|
||||||
|
high_resolution_clock::time_point t2 = high_resolution_clock::now();
|
||||||
|
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
|
||||||
|
cout << "It took me " << time_span.count() << " seconds compare " << numImages << " images from disk cache." << endl;
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
int filecount = 0;
|
int filecount = 0;
|
||||||
for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
//for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
||||||
if (!itr->path().has_extension()) continue; //skip directories and such
|
for (vector<fs::path>::iterator itr = images.begin() ; itr != images.end(); ++itr) {
|
||||||
string image_name = itr->path().filename().generic_string();
|
//if (!itr->path().has_extension()) continue; //skip directories and such
|
||||||
string image_path = itr->path().string();
|
string image_name = (*itr).filename().generic_string();
|
||||||
|
string image_path = (*itr).string();
|
||||||
{ //Progress bar
|
{ //Progress bar
|
||||||
filecount++;
|
filecount++;
|
||||||
cout << setw(60) << setfill('*') << "\r" << string(60, ' ') << flush;
|
cout << setw(60) << setfill('*') << "\r" << string(60, ' ') << flush;
|
||||||
@@ -149,7 +160,22 @@ void DescriptorManager::Init() {
|
|||||||
}
|
}
|
||||||
if (current_image) delete current_image;
|
if (current_image) delete current_image;
|
||||||
current_image = NULL;
|
current_image = NULL;
|
||||||
SaveToDisk();
|
//SaveToDisk();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Copies the features from the old map to the new vector
|
||||||
|
//Should only need to be called once.
|
||||||
|
void DescriptorManager::CopyFeatures() {
|
||||||
|
for (int method = 0; method < numDescriptors; method++) {
|
||||||
|
for (map<string, uint64_t>::iterator it = features[method].begin(); it != features[method].end(); ++it) {
|
||||||
|
features_vector[method].push_back(*it);
|
||||||
|
}
|
||||||
|
for (int mutation = 0; mutation < numMutations; mutation++) {
|
||||||
|
for (map<string, uint64_t>::iterator mit = mutatedFeatures[method][mutation].begin(); mit != mutatedFeatures[method][mutation].end(); ++mit) {
|
||||||
|
mutatedFeatures_vector[method][mutation].push_back(*mit);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,30 +183,19 @@ void DescriptorManager::Init() {
|
|||||||
//skips checking all images we already have.
|
//skips checking all images we already have.
|
||||||
//If only one part is missing, we mark the image for recalculation
|
//If only one part is missing, we mark the image for recalculation
|
||||||
void DescriptorManager::CompareFeatures() {
|
void DescriptorManager::CompareFeatures() {
|
||||||
vector<pair<string, uint64_t>> features_vector;
|
//vector<pair<string, uint64_t>> features_vector;
|
||||||
vector<pair<string, uint64_t>> mutatedFeatures_vector[numMutations];
|
//vector<pair<string, uint64_t>> mutatedFeatures_vector[numMutations];
|
||||||
for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
for (fs::directory_iterator itr(img_path); itr != fs::directory_iterator(); ++itr) {
|
||||||
if (!itr->path().has_extension()) continue; //skip directories and such
|
if (!itr->path().has_extension()) continue; //skip directories and such
|
||||||
string image_name = itr->path().filename().generic_string();
|
string image_name = itr->path().filename().generic_string();
|
||||||
{ //Progress bar
|
for (int method = 0; method < numDescriptors; method++) {
|
||||||
filecount++;
|
if (features[method].count(image_name) == 0){
|
||||||
cout << setw(60) << setfill('*') << "\r" << string(60, ' ') << flush;
|
images.push_back(itr->path());
|
||||||
cout << setfill('*') << setw(60) << right<< "\rChecking which images we already have: " << filecount*100/numImages << "% - (" << filecount << "/" << numImages << "): " << image_name << flush;
|
|
||||||
}
|
}
|
||||||
|
//No need to check for mutated features, because they are always calculated and saved together
|
||||||
for (int method = 0; method < numDescriptors; i++) {
|
|
||||||
bool load = false;
|
|
||||||
if (features[method].count(image_name) == 0) {
|
|
||||||
load = true;
|
|
||||||
}
|
|
||||||
for (int mutation = 0; !load && mutation < numMutations; mutation++) {
|
|
||||||
if (mutatedFeatures[method][mutation].count(image_name) == 0) {
|
|
||||||
load = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (load) images.push_back(itr->path());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cout << "IMAGES: " << images.size() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Saves feature map to disk.
|
//Saves feature map to disk.
|
||||||
|
|||||||
+5
-4
@@ -44,7 +44,8 @@ public:
|
|||||||
void LoadMutationFeatures(string image_path, string image_name, int mutation);
|
void LoadMutationFeatures(string image_path, string image_name, int mutation);
|
||||||
Image* GetMutated(Image* image, string image_name, int method);
|
Image* GetMutated(Image* image, string image_name, int method);
|
||||||
void Init();
|
void Init();
|
||||||
void CompareFeatures()
|
void CopyFeatures();
|
||||||
|
void CompareFeatures();
|
||||||
void SaveToDisk();
|
void SaveToDisk();
|
||||||
void LoadFromDisk();
|
void LoadFromDisk();
|
||||||
void rankImages(string image_name, int method);
|
void rankImages(string image_name, int method);
|
||||||
@@ -68,9 +69,9 @@ private:
|
|||||||
//TODO: Are maps the best container for us? Logarithmic random access is bad, but otherwise it might be fine?
|
//TODO: Are maps the best container for us? Logarithmic random access is bad, but otherwise it might be fine?
|
||||||
map<string, uint64_t> features[numDescriptors]; //array of maps that will hold the descriptors
|
map<string, uint64_t> features[numDescriptors]; //array of maps that will hold the descriptors
|
||||||
map<string, uint64_t> mutatedFeatures[numDescriptors][numMutations];
|
map<string, uint64_t> mutatedFeatures[numDescriptors][numMutations];
|
||||||
vector<pair<string, uint64_t>> features_vector;
|
vector<pair<string, uint64_t>> features_vector[numDescriptors];
|
||||||
vector<pair<string, uint64_t>> mutatedFeatures_vector[numMutations];
|
vector<pair<string, uint64_t>> mutatedFeatures_vector[numDescriptors][numMutations];
|
||||||
vector<fs::Path> images;
|
vector<fs::path> images;
|
||||||
multiset<pair<uint64_t, string> > distances; //multiset that stores the distances
|
multiset<pair<uint64_t, string> > distances; //multiset that stores the distances
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ int main(int argc, char **argv) {
|
|||||||
manager->rankImages(imagename, method);
|
manager->rankImages(imagename, method);
|
||||||
manager->outputRank(imagename, method);
|
manager->outputRank(imagename, method);
|
||||||
manager->outputMap(method);*/
|
manager->outputMap(method);*/
|
||||||
cout << endl;
|
/*cout << endl;
|
||||||
const int thread_count = 8;
|
const int thread_count = 8;
|
||||||
thread* thrds[thread_count];
|
thread* thrds[thread_count];
|
||||||
for (int i =0; i < thread_count; i++) {
|
for (int i =0; i < thread_count; i++) {
|
||||||
@@ -39,7 +39,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
for (int i =0; i < thread_count; i++) {
|
for (int i =0; i < thread_count; i++) {
|
||||||
thrds[i]->join();
|
thrds[i]->join();
|
||||||
}
|
}*/
|
||||||
//manager->test();
|
//manager->test();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user