-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindexer_launcher.cpp
More file actions
executable file
·145 lines (136 loc) · 4.62 KB
/
Copy pathindexer_launcher.cpp
File metadata and controls
executable file
·145 lines (136 loc) · 4.62 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2012 Yandex Artem Babenko
#include <iostream>
#include <boost/program_options.hpp>
#include "indexer.h"
using namespace boost::program_options;
/**
* Number of threads for indexing
*/
int THREADS_COUNT;
/**
* Type, should be BVEC or FVEC
*/
PointType point_type;
/**
* Number of coordinates in a point
*/
Dimensions SPACE_DIMENSION;
/**
* File with vocabularies for multiindex structure
*/
string coarse_vocabs_file;
/**
* File with vocabularies for reranking
*/
string fine_vocabs_file;
/**
* File with points to index
*/
string points_file;
/**
* File with points metainfo (imageId, etc.)
*/
string metainfo_file;
/**
* Reranking approach, should be USE_RESIDUALS or USE_INIT_POINTS
*/
RerankMode mode;
/**
* Common prefix of all multiindex files
*/
string files_prefix;
/**
* Should we calculate coarse quantizations (they can be precomputed)
*/
bool build_coarse_quantizations;
/**
* File with points coarse quantizations
*/
string coarse_quantizations_file;
/**
* How many points should we index
*/
int points_count;
/**
* Multiplicity of multiindex
*/
int multiplicity;
int SetOptions(int argc, char** argv) {
options_description description("Options");
description.add_options()
("threads_count,t", value<int>())
("multiplicity,m", value<int>())
("points_file,p", value<string>())
("metainfo_file,z", value<string>())
("coarse_vocabs_file,c", value<string>())
("fine_vocabs_file,f", value<string>())
("input_point_type,i", value<string>())
("build_coarse,b", bool_switch(), "Flag B")
("use_residuals,r", bool_switch(), "Flag R")
("points_count,p", value<int>())
("coarse_quantization_file,q", value<string>())
("space_dim,d", value<int>())
("files_prefix,_", value<string>());
variables_map name_to_value;
try {
store(command_line_parser(argc, argv).options(description).run(), name_to_value);
} catch (const invalid_command_line_syntax& inv_syntax) {
switch (inv_syntax.kind()) {
case invalid_syntax::missing_parameter :
cout << "Missing argument for option '" << inv_syntax.tokens() << "'.\n";
break;
default:
cout << "Syntax error, kind " << int(inv_syntax.kind()) << "\n";
break;
};
return 1;
} catch (const unknown_option& unkn_option) {
cout << "Unknown option '" << unkn_option.get_option_name() << "'\n";
return 1;
}
if (name_to_value.count("help")) {
cout << description << "\n";
return 1;
}
THREADS_COUNT = name_to_value["threads_count"].as<int>();
multiplicity = name_to_value["multiplicity"].as<int>();
points_file = name_to_value["points_file"].as<string>();
metainfo_file = name_to_value["metainfo_file"].as<string>();
coarse_vocabs_file = name_to_value["coarse_vocabs_file"].as<string>();
fine_vocabs_file = name_to_value["fine_vocabs_file"].as<string>();
SPACE_DIMENSION = name_to_value["space_dim"].as<int>();
files_prefix = name_to_value["files_prefix"].as<string>();
points_count = name_to_value["points_count"].as<int>();
build_coarse_quantizations = (name_to_value["build_coarse"].as<bool>() == true) ? true : false;
mode = name_to_value["use_residuals"].as<bool>() == true ? USE_RESIDUALS : USE_INIT_POINTS;
if (name_to_value.find("coarse_quantization_file") != name_to_value.end()) {
coarse_quantizations_file = name_to_value["coarse_quantization_file"].as<string>();
}
if (name_to_value["input_point_type"].as<string>() == "FVEC") {
point_type = FVEC;
} else if(name_to_value["input_point_type"].as<string>() == "BVEC") {
point_type = BVEC;
}
return 0;
}
int main(int argc, char** argv) {
SetOptions(argc, argv);
cout << "Options are set ...\n";
vector<Centroids> coarse_vocabs;
vector<Centroids> fine_vocabs;
ReadVocabularies<float>(coarse_vocabs_file, SPACE_DIMENSION, &coarse_vocabs);
ReadFineVocabs<float>(fine_vocabs_file, &fine_vocabs);
cout << "Vocs are read ...\n";
if(fine_vocabs.size() == 8) {
MultiIndexer<RerankADC8> indexer(multiplicity);
indexer.BuildMultiIndex(points_file, metainfo_file, points_count, coarse_vocabs,
fine_vocabs, mode, build_coarse_quantizations,
files_prefix, coarse_quantizations_file);
} else if(fine_vocabs.size() == 16) {
MultiIndexer<RerankADC16> indexer(multiplicity);
indexer.BuildMultiIndex(points_file, metainfo_file, points_count, coarse_vocabs,
fine_vocabs, mode, build_coarse_quantizations,
files_prefix, coarse_quantizations_file);
}
return 0;
}