|
vocabtree
0.0.1
|
#include <vocab_tree.hpp>


Data Structures | |
| struct | MatchResults |
| Subclass of match results base which also returns scores. More... | |
| struct | SearchParams |
| Subclass of train params base which specifies Vocab Tree training parameters. More... | |
| struct | TrainParams |
| Subclass of train params base which specifies vocab tree training parameters. More... | |
| struct | TreeNode |
Public Member Functions | |
| VocabTree () | |
| bool | train (Dataset &dataset, const std::shared_ptr< const TrainParamsBase > ¶ms, const std::vector< std::shared_ptr< const Image > > &examples) |
| Given a set of training parameters, list of images, trains. More... | |
| bool | load (const std::string &file_path) |
| Loads a trained search structure from the input filepath. More... | |
| bool | save (const std::string &file_path) const |
| Saves a trained search structure to the input filepath. More... | |
| std::shared_ptr< MatchResultsBase > | search (Dataset &dataset, const std::shared_ptr< const SearchParamsBase > ¶ms, const std::shared_ptr< const Image > &example) |
| Given a set of search parameters, a query image, searches for matching images and returns the match. More... | |
| uint32_t | tree_splits () const |
| returns the split size of each node More... | |
| uint32_t | tree_depth () const |
| returns the depth size of tree More... | |
Public Member Functions inherited from SearchBase | |
| SearchBase () | |
| SearchBase (const std::string &file_path) | |
| virtual | ~SearchBase () |
| std::vector< std::shared_ptr < MatchResultsBase > > | search (Dataset &dataset, const std::shared_ptr< SearchParamsBase > ¶ms, const std::vector< std::shared_ptr< const Image > > &examples) |
| Given a set of search parameters, list of query images, searches for matching images and returns the result matches. More... | |
Protected Member Functions | |
| void | buildTreeRecursive (uint32_t t, const cv::Mat &descriptors, cv::TermCriteria &tc, int attempts, int flags, int currLevel) |
| Recursively builds a tree, starting with 0 and ending with currLevel = maxLevel-1. More... | |
| std::vector< float > | generateVector (const cv::Mat &descriptors, bool shouldWeight, int64_t id=-1) |
| helper function, inserts a dummy possibleMatches More... | |
| std::vector< float > | generateVector (const cv::Mat &descriptors, bool shouldWeight, std::unordered_set< uint32_t > &possibleMatches, int64_t id=-1) |
| To call with an id call without possibleMatches and it will go to the helper function Takes descriptors for an image and for each descriptor finds the path down the tree generating a vector (describing the path) Adds up all vectors (one from each descriptor) to return the vector of counts for each node If shouldWeight is true will weight each by the weight of the node, should be true for general query and false for construction If id is set then will insert that id into the invertedFile of each leaf visited, if negative or not set then won't do anything When id is not set will use insert images into possibleMatches, possibleMatches will not be used if id is set. More... | |
| void | generateVectorHelper (uint32_t nodeIndex, const cv::Mat &descriptor, std::vector< float > &counts, std::unordered_set< uint32_t > &possibleMatches, int64_t id=-1) |
| Recursive function that recursively goes down the tree from t to find where the single descriptor belongs (stopping at leaf) On each node increments cound in the counts vector If id is set (>=0) then adds the image with that id to the leaf Picks the child to traverse down based on the max dot product. More... | |
Protected Attributes | |
| uint32_t | split |
| stores the amount of splits used to generate tree More... | |
| uint32_t | maxLevel |
| Stores the max level of the tree. More... | |
| uint32_t | numberOfNodes |
| number of nodes the tree will have, saved in variable so don't have to recompute More... | |
| std::vector< float > | weights |
| std::vector< TreeNode > | tree |
| std::vector < std::unordered_map< uint64_t, uint32_t > > | invertedFiles |
| std::unordered_map< uint64_t, std::vector< float > > | databaseVectors |
| Stores the database vectors for all images in the database - d_i in the paper Indexes by the image id. More... | |
Definition at line 7 of file vocab_tree.hpp.
| VocabTree::VocabTree | ( | ) |
Definition at line 17 of file vocab_tree.cxx.
|
protected |
|
protected |
helper function, inserts a dummy possibleMatches
Definition at line 331 of file vocab_tree.cxx.
Referenced by search(), and train().
|
protected |
To call with an id call without possibleMatches and it will go to the helper function Takes descriptors for an image and for each descriptor finds the path down the tree generating a vector (describing the path) Adds up all vectors (one from each descriptor) to return the vector of counts for each node If shouldWeight is true will weight each by the weight of the node, should be true for general query and false for construction If id is set then will insert that id into the invertedFile of each leaf visited, if negative or not set then won't do anything When id is not set will use insert images into possibleMatches, possibleMatches will not be used if id is set.
Definition at line 336 of file vocab_tree.cxx.
References generateVectorHelper(), numberOfNodes, and weights.
|
protected |
Recursive function that recursively goes down the tree from t to find where the single descriptor belongs (stopping at leaf) On each node increments cound in the counts vector If id is set (>=0) then adds the image with that id to the leaf Picks the child to traverse down based on the max dot product.
Definition at line 367 of file vocab_tree.cxx.
References invertedFiles, split, and tree.
Referenced by generateVector().
|
virtual |
Loads a trained search structure from the input filepath.
Implements SearchBase.
Definition at line 29 of file vocab_tree.cxx.
References cvmat_header::cols, databaseVectors, cvmat_header::elem_size, cvmat_header::elem_type, invertedFiles, maxLevel, numberOfNodes, cvmat_header::rows, split, tree, and weights.
|
virtual |
Saves a trained search structure to the input filepath.
Implements SearchBase.
Definition at line 90 of file vocab_tree.cxx.
References cvmat_header::cols, databaseVectors, cvmat_header::elem_size, cvmat_header::elem_type, VocabTree::TreeNode::firstChildIndex, VocabTree::TreeNode::index, VocabTree::TreeNode::invertedFileLength, invertedFiles, VocabTree::TreeNode::level, VocabTree::TreeNode::levelIndex, maxLevel, VocabTree::TreeNode::mean, numberOfNodes, cvmat_header::rows, split, tree, and weights.
Referenced by train_tree().
|
virtual |
Given a set of search parameters, a query image, searches for matching images and returns the match.
Implements SearchBase.
Definition at line 415 of file vocab_tree.cxx.
References databaseVectors, filesystem::file_exists(), generateVector(), invertedFiles, filesystem::load_cvmat(), Dataset::location(), and numberOfNodes.
Referenced by main().
|
virtual |
Given a set of training parameters, list of images, trains.
Returns true if successful, false if not successful.
Implements SearchBase.
Definition at line 145 of file vocab_tree.cxx.
References buildTreeRecursive(), databaseVectors, filesystem::file_exists(), generateVector(), Dataset::image(), invertedFiles, filesystem::load_cvmat(), Dataset::location(), maxLevel, vision::merge_descriptors(), numberOfNodes, split, tree, and weights.
Referenced by main(), and train_tree().
| uint32_t VocabTree::tree_depth | ( | ) | const |
| uint32_t VocabTree::tree_splits | ( | ) | const |
returns the split size of each node
Definition at line 491 of file vocab_tree.cxx.
References split.
|
protected |
|
protected |
Definition at line 79 of file vocab_tree.hpp.
Referenced by generateVectorHelper(), load(), save(), search(), and train().
|
protected |
Stores the max level of the tree.
Definition at line 72 of file vocab_tree.hpp.
Referenced by buildTreeRecursive(), load(), save(), train(), and tree_depth().
|
protected |
number of nodes the tree will have, saved in variable so don't have to recompute
Definition at line 74 of file vocab_tree.hpp.
Referenced by generateVector(), load(), save(), search(), and train().
|
protected |
stores the amount of splits used to generate tree
Definition at line 70 of file vocab_tree.hpp.
Referenced by buildTreeRecursive(), generateVectorHelper(), load(), main(), save(), train(), train_tree(), and tree_splits().
|
protected |
Definition at line 78 of file vocab_tree.hpp.
Referenced by buildTreeRecursive(), generateVectorHelper(), load(), save(), and train().
|
protected |
Definition at line 76 of file vocab_tree.hpp.
Referenced by generateVector(), load(), save(), and train().