vocabtree  0.0.1
compute_index_simple.cxx
Go to the documentation of this file.
1 #include "tests_config.hpp"
2 
3 #include <utils/filesystem.hpp>
4 #include <utils/numerics.hpp>
5 #include <utils/dataset.hpp>
6 #include <utils/vision.hpp>
7 #include <utils/logger.hpp>
10 
11 #include <iostream>
12 
13 #if ENABLE_MULTITHREADING && ENABLE_OPENMP
14 #include <omp.h>
15 #endif
16 #if ENABLE_MULTITHREADING && ENABLE_MPI
17 #include <mpi.h>
18 #endif
19 
20 _INITIALIZE_EASYLOGGINGPP
21 
22 int main(int argc, char *argv[]) {
23 #if ENABLE_MULTITHREADING && ENABLE_MPI
24  MPI::Init(argc, argv);
25  int rank = MPI::COMM_WORLD.Get_rank();
26  if(rank == 0) {
27 #endif
28  const uint32_t num_clusters = 512;
29 
31  LINFO << simple_dataset;
32 
33  std::stringstream vocab_output_file;
34  vocab_output_file << simple_dataset.location() << "/vocabulary/" << num_clusters << ".vocab";
35 
36  std::shared_ptr<BagOfWords> bow = std::make_shared<BagOfWords>(vocab_output_file.str());
37 
38  InvertedIndex ii;
39  std::shared_ptr<InvertedIndex::TrainParams> train_params = std::make_shared<InvertedIndex::TrainParams>();
40  train_params->bag_of_words = bow;
41  ii.train(simple_dataset, train_params, simple_dataset.all_images());
42 
43  std::stringstream index_output_file;
44  index_output_file << simple_dataset.location() << "/index/" << num_clusters << ".index";
45  filesystem::create_file_directory(index_output_file.str());
46  ii.save(index_output_file.str());
47 #if ENABLE_MULTITHREADING && ENABLE_MPI
48  }
49  MPI::Finalize();
50 #endif
51  return 0;
52 }