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 | 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 | 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 294 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 435 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const std::string & | filename | ) |
Creates the vocabulary by loading a file
filename |
Definition at line 446 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const char * | filename | ) |
Creates the vocabulary by loading a file
filename |
Definition at line 455 of file TemplatedVocabulary.h.
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const TemplatedVocabulary< TDescriptor, F > & | voc | ) |
|
virtual |
Destructor
Definition at line 527 of file TemplatedVocabulary.h.
|
virtual |
Creates a vocabulary from the training features with the already defined parameters
training_features |
Definition at line 558 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 592 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 605 of file TemplatedVocabulary.h.
|
protected |
Creates an instance of the scoring object accoring to m_scoring
Definition at line 463 of file TemplatedVocabulary.h.
|
protected |
Create the words of the vocabulary once the tree has been built
Definition at line 918 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns whether the vocabulary is empty (i.e. it has not been trained)
Definition at line 1009 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 1017 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 621 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 1265 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 1034 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 1280 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns the weight of a word
wid | word id |
Definition at line 1042 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 642 of file TemplatedVocabulary.h.
|
protectedvirtual |
Creates k clusters from the given descriptors with some seeding algorithm.
Definition at line 825 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 833 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load | ( | const std::string & | filename | ) |
Loads the vocabulary from a file
filename |
Definition at line 1465 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 1573 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 1338 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 537 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 1454 of file TemplatedVocabulary.h.
|
virtual |
Saves the vocabulary to a file storage structure
fn | node in file storage |
Definition at line 1476 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 1429 of file TemplatedVocabulary.h.
|
inline |
Returns the score of two vectors
a | vector |
b | vector |
Definition at line 1200 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 944 of file TemplatedVocabulary.h.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setScoringType | ( | ScoringType | type | ) |
Changes the scoring method
type | new scoring type |
Definition at line 500 of file TemplatedVocabulary.h.
|
inline |
Changes the weighting method
type | new weighting type |
Definition at line 509 of file TemplatedVocabulary.h.
|
inlinevirtual |
Returns the number of words in the vocabulary
Definition at line 1001 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 1320 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 1066 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 1127 of file TemplatedVocabulary.h.
|
virtual |
Transforms a single feature into a word (without weight)
feature |
Definition at line 1051 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 1218 of file TemplatedVocabulary.h.
|
protectedvirtual |
Returns the word id associated to a feature
feature | |
id | (out) word id |
Definition at line 1209 of file TemplatedVocabulary.h.
|
protected |
Branching factor.
Definition at line 408 of file TemplatedVocabulary.h.
|
protected |
Depth levels.
Definition at line 411 of file TemplatedVocabulary.h.
|
protected |
Tree nodes.
Definition at line 423 of file TemplatedVocabulary.h.
|
protected |
Scoring method.
Definition at line 417 of file TemplatedVocabulary.h.
|
protected |
Object for computing scores.
Definition at line 420 of file TemplatedVocabulary.h.
|
protected |
Weighting method.
Definition at line 414 of file TemplatedVocabulary.h.
|
protected |
Words of the vocabulary (tree leaves) this condition holds: m_words[wid]->word_id == wid
Definition at line 427 of file TemplatedVocabulary.h.