-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexing.cpp
68 lines (54 loc) · 1.63 KB
/
indexing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <vector>
#include <nlohmann/json.hpp>
#include <fstream>
#include "inc/SStree.h"
struct ImageData {
std::vector<Point> embeddings;
std::vector<std::string> paths;
};
ImageData readEmbeddingsFromJson(const std::string& FILE_NAME) {
ImageData data;
data.embeddings.reserve(26179);
data.paths.reserve(26179);
try {
std::ifstream file(FILE_NAME);
if (!file.is_open()) {
throw std::runtime_error("Unable to open JSON file.");
}
nlohmann::json jsonData;
file >> jsonData;
for (auto it = jsonData.begin(); it != jsonData.end(); ++it) {
const std::string& path = it.key();
std::vector<float> values = it.value();
std::vector<NType> embedding;
embedding.reserve(values.size());
for (auto& x: values) {
embedding.emplace_back(x);
}
data.embeddings.emplace_back(embedding);
data.paths.push_back(path);
}
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
return data;
}
int main() {
const std::string FILE_NAME("embedding.json");
ImageData data = readEmbeddingsFromJson(FILE_NAME);
SsTree tree(448);
std::cout << "Begin\n";
for (int i = 0; i < data.embeddings.size(); ++i) {
tree.insert(data.embeddings[i], data.paths[i]);
if ((i+1)%100 == 0) {
std::cout << (i+1) << ": " << "\n";
tree.print();
tree.test();
}
}
std::cout << "End\n";
tree.print();
tree.test();
tree.saveToFile("tree.dat");
}