Generic Vocabulary. More...
#include <TemplatedVocabulary.h>
Classes | |
struct | Node |
Tree node. More... | |
Public Member Functions | |
virtual void | create (const std::vector< std::vector< TDescriptor > > &training_features) |
virtual void | create (const std::vector< std::vector< TDescriptor > > &training_features, int k, int L) |
virtual void | create (const std::vector< std::vector< TDescriptor > > &training_features, int k, int L, WeightingType weighting, ScoringType scoring) |
virtual bool | empty () const |
int | getBranchingFactor () const |
int | getDepthLevels () const |
float | getEffectiveLevels () const |
virtual NodeId | getParentNode (WordId wid, int levelsup) const |
ScoringType | getScoringType () const |
WeightingType | getWeightingType () const |
virtual TDescriptor | getWord (WordId wid) const |
void | getWordsFromNode (NodeId nid, std::vector< WordId > &words) const |
virtual WordValue | getWordWeight (WordId wid) const |
void | load (const std::string &filename) |
virtual void | load (const cv::FileStorage &fs, const std::string &name="vocabulary") |
bool | loadFromBinFile (const std::string &filename) |
bool | loadFromTextFile (const std::string &filename) |
TemplatedVocabulary< TDescriptor, F > & | operator= (const TemplatedVocabulary< TDescriptor, F > &voc) |
void | save (const std::string &filename) const |
virtual void | save (cv::FileStorage &fs, const std::string &name="vocabulary") const |
void | saveToBinFile (const std::string &filename) const |
void | saveToTextFile (const std::string &filename) const |
double | score (const BowVector &a, const BowVector &b) const |
void | setScoringType (ScoringType type) |
void | setWeightingType (WeightingType type) |
virtual unsigned int | size () const |
virtual int | stopWords (double minWeight) |
TemplatedVocabulary (int k=10, int L=5, WeightingType weighting=TF_IDF, ScoringType scoring=L1_NORM) | |
TemplatedVocabulary (const std::string &filename) | |
TemplatedVocabulary (const char *filename) | |
TemplatedVocabulary (const TemplatedVocabulary< TDescriptor, F > &voc) | |
virtual void | transform (const std::vector< TDescriptor > &features, BowVector &v) const |
virtual void | transform (const std::vector< TDescriptor > &features, BowVector &v, FeatureVector &fv, int levelsup) const |
virtual WordId | transform (const TDescriptor &feature) const |
virtual | ~TemplatedVocabulary () |
Protected Types | |
typedef const TDescriptor * | pDescriptor |
Pointer to descriptor. More... | |
Protected Member Functions | |
void | createScoringObject () |
void | createWords () |
void | getFeatures (const vector< vector< TDescriptor > > &training_features, vector< pDescriptor > &features) const |
void | HKmeansStep (NodeId parent_id, const vector< pDescriptor > &descriptors, int current_level) |
virtual void | initiateClusters (const vector< pDescriptor > &descriptors, vector< TDescriptor > &clusters) const |
void | initiateClustersKMpp (const vector< pDescriptor > &descriptors, vector< TDescriptor > &clusters) const |
void | setNodeWeights (const vector< vector< TDescriptor > > &features) |
virtual void | transform (const TDescriptor &feature, WordId &id, WordValue &weight, NodeId *nid=NULL, int levelsup=0) const |
virtual void | transform (const TDescriptor &feature, WordId &id) const |
Protected Attributes | |
int | m_k |
Branching factor. More... | |
int | m_L |
Depth levels. More... | |
std::vector< Node > | m_nodes |
Tree nodes. More... | |
ScoringType | m_scoring |
Scoring method. More... | |
GeneralScoring * | m_scoring_object |
Object for computing scores. More... | |
WeightingType | m_weighting |
Weighting method. More... | |
std::vector< Node * > | m_words |
Generic Vocabulary.
TDescriptor | class of descriptor |
F | class of descriptor functions |
Definition at line 44 of file TemplatedVocabulary.h.
|
protected |
Pointer to descriptor.
Definition at line 307 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | int | k = 10 , |
int | L = 5 , |
||
WeightingType | weighting = TF_IDF , |
||
ScoringType | scoring = L1_NORM |
||
) |
Initiates an empty vocabulary
k | branching factor |
L | depth levels |
weighting | weighting type |
scoring | scoring type |
Definition at line 448 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const std::string & | filename | ) |
Creates the vocabulary by loading a file
filename |
Definition at line 459 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const char * | filename | ) |
Creates the vocabulary by loading a file
filename |
Definition at line 468 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const TemplatedVocabulary< TDescriptor, F > & | voc | ) |
|
virtual |
Destructor
Definition at line 540 of file TemplatedVocabulary.h.
|
virtual |
Creates a vocabulary from the training features with the already defined parameters
training_features |
Definition at line 571 of file TemplatedVocabulary.h.
|
virtual |
Creates a vocabulary from the training features, setting the branching factor and the depth levels of the tree
training_features | |
k | branching factor |
L | depth levels |
Definition at line 605 of file TemplatedVocabulary.h.
|
virtual |
Creates a vocabulary from the training features, setting the branching factor nad the depth levels of the tree, and the weighting and scoring schemes
Definition at line 618 of file TemplatedVocabulary.h.
|
protected |
Creates an instance of the scoring object accoring to m_scoring
Definition at line 476 of file TemplatedVocabulary.h.
|
protected |
Create the words of the vocabulary once the tree has been built
Definition at line 931 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns whether the vocabulary is empty (i.e. it has not been trained)
Definition at line 1022 of file TemplatedVocabulary.h.
|
inline |
Returns the branching factor of the tree (k)
Definition at line 185 of file TemplatedVocabulary.h.
|
inline |
Returns the depth levels of the tree (L)
Definition at line 191 of file TemplatedVocabulary.h.
float DBoW2::TemplatedVocabulary< TDescriptor, F >::getEffectiveLevels | ( | ) | const |
Returns the real depth levels of the tree on average
Definition at line 1030 of file TemplatedVocabulary.h.
|
protected |
Returns a set of pointers to descriptores
training_features | all the features |
features | (out) pointers to the training features |
Definition at line 634 of file TemplatedVocabulary.h.
|
virtual |
Returns the id of the node that is "levelsup" levels from the word given
wid | word id |
levelsup | 0..L |
Definition at line 1278 of file TemplatedVocabulary.h.
|
inline |
Returns the scoring method
Definition at line 223 of file TemplatedVocabulary.h.
|
inline |
Returns the weighting method
Definition at line 217 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns the descriptor of a word
wid | word id |
Definition at line 1047 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordsFromNode | ( | NodeId | nid, |
std::vector< WordId > & | words | ||
) | const |
Returns the ids of all the words that are under the given node id, by traversing any of the branches that goes down from the node
nid | starting node id |
words | ids of words |
Definition at line 1293 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns the weight of a word
wid | word id |
Definition at line 1055 of file TemplatedVocabulary.h.
|
protected |
Creates a level in the tree, under the parent, by running kmeans with a descriptor set, and recursively creates the subsequent levels too
parent_id | id of parent node |
descriptors | descriptors to run the kmeans on |
current_level | current level in the tree |
Definition at line 655 of file TemplatedVocabulary.h.
|
protectedvirtual |
Creates k clusters from the given descriptors with some seeding algorithm.
Definition at line 838 of file TemplatedVocabulary.h.
|
protected |
Creates k clusters from the given descriptor sets by running the initial step of kmeans++
descriptors | |
clusters | resulting clusters |
Definition at line 846 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load | ( | const std::string & | filename | ) |
Loads the vocabulary from a file
filename |
Definition at line 1594 of file TemplatedVocabulary.h.
|
virtual |
Loads the vocabulary from a file storage node
fn | first node |
subname | name of the child node of fn where the tree is stored. If not given, the fn node is used instead |
Definition at line 1702 of file TemplatedVocabulary.h.
bool DBoW2::TemplatedVocabulary< TDescriptor, F >::loadFromBinFile | ( | const std::string & | filename | ) |
Loads the vocabulary from a binary file
filename |
Definition at line 1473 of file TemplatedVocabulary.h.
bool DBoW2::TemplatedVocabulary< TDescriptor, F >::loadFromTextFile | ( | const std::string & | filename | ) |
Loads the vocabulary from a text file
filename |
Definition at line 1351 of file TemplatedVocabulary.h.
TemplatedVocabulary< TDescriptor, F > & DBoW2::TemplatedVocabulary< TDescriptor, F >::operator= | ( | const TemplatedVocabulary< TDescriptor, F > & | voc | ) |
Assigns the given vocabulary to this by copying its data and removing all the data contained by this vocabulary before
voc |
Definition at line 550 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save | ( | const std::string & | filename | ) | const |
Saves the vocabulary into a file
filename |
Definition at line 1583 of file TemplatedVocabulary.h.
|
virtual |
Saves the vocabulary to a file storage structure
fn | node in file storage |
Definition at line 1605 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::saveToBinFile | ( | const std::string & | filename | ) | const |
Saves the vocabulary into a binary file
filename |
Definition at line 1551 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::saveToTextFile | ( | const std::string & | filename | ) | const |
Saves the vocabulary into a text file
filename |
Definition at line 1448 of file TemplatedVocabulary.h.
|
inline |
Returns the score of two vectors
a | vector |
b | vector |
Definition at line 1213 of file TemplatedVocabulary.h.
|
protected |
Sets the weights of the nodes of tree according to the given features. Before calling this function, the nodes and the words must be already created (by calling HKmeansStep and createWords)
features |
Definition at line 957 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setScoringType | ( | ScoringType | type | ) |
Changes the scoring method
type | new scoring type |
Definition at line 513 of file TemplatedVocabulary.h.
|
inline |
Changes the weighting method
type | new weighting type |
Definition at line 522 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns the number of words in the vocabulary
Definition at line 1014 of file TemplatedVocabulary.h.
|
virtual |
Stops those words whose weight is below minWeight. Words are stopped by setting their weight to 0. There are not returned later when transforming image features into vectors. Note that when using IDF or TF_IDF, the weight is the idf part, which is equivalent to -log(f), where f is the frequency of the word (f = Ni/N, Ni: number of training images where the word is present, N: number of training images). Note that the old weight is forgotten, and subsequent calls to this function with a lower minWeight have no effect.
Definition at line 1333 of file TemplatedVocabulary.h.
|
virtual |
Transforms a set of descriptores into a bow vector
features | |
v | (out) bow vector of weighted words |
Definition at line 1079 of file TemplatedVocabulary.h.
|
virtual |
Transform a set of descriptors into a bow vector and a feature vector
features | |
v | (out) bow vector |
fv | (out) feature vector of nodes and feature indexes |
levelsup | levels to go up the vocabulary tree to get the node index |
Definition at line 1140 of file TemplatedVocabulary.h.
|
virtual |
Transforms a single feature into a word (without weight)
feature |
Definition at line 1064 of file TemplatedVocabulary.h.
|
protectedvirtual |
Returns the word id associated to a feature
feature | |
id | (out) word id |
weight | (out) word weight |
nid | (out) if given, id of the node "levelsup" levels up |
levelsup |
Definition at line 1231 of file TemplatedVocabulary.h.
|
protectedvirtual |
Returns the word id associated to a feature
feature | |
id | (out) word id |
Definition at line 1222 of file TemplatedVocabulary.h.
|
protected |
Branching factor.
Definition at line 421 of file TemplatedVocabulary.h.
|
protected |
Depth levels.
Definition at line 424 of file TemplatedVocabulary.h.
|
protected |
Tree nodes.
Definition at line 436 of file TemplatedVocabulary.h.
|
protected |
Scoring method.
Definition at line 430 of file TemplatedVocabulary.h.
|
protected |
Object for computing scores.
Definition at line 433 of file TemplatedVocabulary.h.
|
protected |
Weighting method.
Definition at line 427 of file TemplatedVocabulary.h.
|
protected |
Words of the vocabulary (tree leaves) this condition holds: m_words[wid]->word_id == wid
Definition at line 440 of file TemplatedVocabulary.h.