Generic Vocabulary. More...
#include <TemplatedVocabulary.h>
Classes | |
struct | Node |
Tree node. More... | |
Public Member Functions | |
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 | ~TemplatedVocabulary () |
TemplatedVocabulary < TDescriptor, F > & | operator= (const TemplatedVocabulary< TDescriptor, F > &voc) |
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 unsigned int | size () const |
virtual bool | empty () const |
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 |
double | score (const BowVector &a, const BowVector &b) const |
virtual NodeId | getParentNode (WordId wid, int levelsup) const |
void | getWordsFromNode (NodeId nid, std::vector< WordId > &words) const |
int | getBranchingFactor () const |
int | getDepthLevels () const |
float | getEffectiveLevels () const |
virtual TDescriptor | getWord (WordId wid) const |
virtual WordValue | getWordWeight (WordId wid) const |
WeightingType | getWeightingType () const |
ScoringType | getScoringType () const |
void | setWeightingType (WeightingType type) |
void | setScoringType (ScoringType type) |
void | save (const std::string &filename) const |
void | load (const std::string &filename) |
virtual void | save (cv::FileStorage &fs, const std::string &name="vocabulary") const |
virtual void | load (const cv::FileStorage &fs, const std::string &name="vocabulary") |
virtual int | stopWords (double minWeight) |
Protected Types | |
typedef const TDescriptor * | pDescriptor |
Pointer to descriptor. | |
Protected Member Functions | |
void | createScoringObject () |
void | getFeatures (const vector< vector< TDescriptor > > &training_features, vector< pDescriptor > &features) const |
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 |
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 | createWords () |
void | setNodeWeights (const vector< vector< TDescriptor > > &features) |
Protected Attributes | |
int | m_k |
Branching factor. | |
int | m_L |
Depth levels. | |
WeightingType | m_weighting |
Weighting method. | |
ScoringType | m_scoring |
Scoring method. | |
GeneralScoring * | m_scoring_object |
Object for computing scores. | |
std::vector< Node > | m_nodes |
Tree nodes. | |
std::vector< Node * > | m_words |
Generic Vocabulary.
TDescriptor | class of descriptor | |
F | class of descriptor functions |
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | int | k = 10 , |
|
int | L = 5 , |
|||
WeightingType | weighting = TF_IDF , |
|||
ScoringType | scoring = L1_NORM | |||
) | [inline] |
Initiates an empty vocabulary
k | branching factor | |
L | depth levels | |
weighting | weighting type | |
scoring | scoring type |
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const std::string & | filename | ) | [inline] |
Creates the vocabulary by loading a file
filename |
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const char * | filename | ) | [inline] |
Creates the vocabulary by loading a file
filename |
DBoW2::TemplatedVocabulary< TDescriptor, F >::TemplatedVocabulary | ( | const TemplatedVocabulary< TDescriptor, F > & | voc | ) | [inline] |
Copy constructor
voc |
DBoW2::TemplatedVocabulary< TDescriptor, F >::~TemplatedVocabulary | ( | ) | [inline, virtual] |
Destructor
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create | ( | const std::vector< std::vector< TDescriptor > > & | training_features, | |
int | k, | |||
int | L, | |||
WeightingType | weighting, | |||
ScoringType | scoring | |||
) | [inline, 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
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create | ( | const std::vector< std::vector< TDescriptor > > & | training_features, | |
int | k, | |||
int | L | |||
) | [inline, 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 |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::create | ( | const std::vector< std::vector< TDescriptor > > & | training_features | ) | [inline, virtual] |
Creates a vocabulary from the training features with the already defined parameters
training_features |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::createScoringObject | ( | ) | [inline, protected] |
Creates an instance of the scoring object accoring to m_scoring
void DBoW2::TemplatedVocabulary< TDescriptor, F >::createWords | ( | ) | [inline, protected] |
Create the words of the vocabulary once the tree has been built
bool DBoW2::TemplatedVocabulary< TDescriptor, F >::empty | ( | ) | const [inline, virtual] |
Returns whether the vocabulary is empty (i.e. it has not been trained)
int DBoW2::TemplatedVocabulary< TDescriptor, F >::getBranchingFactor | ( | ) | const [inline] |
Returns the branching factor of the tree (k)
int DBoW2::TemplatedVocabulary< TDescriptor, F >::getDepthLevels | ( | ) | const [inline] |
Returns the depth levels of the tree (L)
float DBoW2::TemplatedVocabulary< TDescriptor, F >::getEffectiveLevels | ( | ) | const [inline] |
Returns the real depth levels of the tree on average
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getFeatures | ( | const vector< vector< TDescriptor > > & | training_features, | |
vector< pDescriptor > & | features | |||
) | const [inline, protected] |
Returns a set of pointers to descriptores
training_features | all the features | |
features | (out) pointers to the training features |
NodeId DBoW2::TemplatedVocabulary< TDescriptor, F >::getParentNode | ( | WordId | wid, | |
int | levelsup | |||
) | const [inline, virtual] |
Returns the id of the node that is "levelsup" levels from the word given
wid | word id | |
levelsup | 0..L |
ScoringType DBoW2::TemplatedVocabulary< TDescriptor, F >::getScoringType | ( | ) | const [inline] |
Returns the scoring method
WeightingType DBoW2::TemplatedVocabulary< TDescriptor, F >::getWeightingType | ( | ) | const [inline] |
Returns the weighting method
TDescriptor DBoW2::TemplatedVocabulary< TDescriptor, F >::getWord | ( | WordId | wid | ) | const [inline, virtual] |
Returns the descriptor of a word
wid | word id |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordsFromNode | ( | NodeId | nid, | |
std::vector< WordId > & | words | |||
) | const [inline] |
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 |
WordValue DBoW2::TemplatedVocabulary< TDescriptor, F >::getWordWeight | ( | WordId | wid | ) | const [inline, virtual] |
Returns the weight of a word
wid | word id |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::HKmeansStep | ( | NodeId | parent_id, | |
const vector< pDescriptor > & | descriptors, | |||
int | current_level | |||
) | [inline, 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 |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::initiateClusters | ( | const vector< pDescriptor > & | descriptors, | |
vector< TDescriptor > & | clusters | |||
) | const [inline, protected, virtual] |
Creates k clusters from the given descriptors with some seeding algorithm.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::initiateClustersKMpp | ( | const vector< pDescriptor > & | descriptors, | |
vector< TDescriptor > & | clusters | |||
) | const [inline, protected] |
Creates k clusters from the given descriptor sets by running the initial step of kmeans++
descriptors | ||
clusters | resulting clusters |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load | ( | const cv::FileStorage & | fs, | |
const std::string & | name = "vocabulary" | |||
) | [inline, 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 |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::load | ( | const std::string & | filename | ) | [inline] |
Loads the vocabulary from a file
filename |
TemplatedVocabulary< TDescriptor, F > & DBoW2::TemplatedVocabulary< TDescriptor, F >::operator= | ( | const TemplatedVocabulary< TDescriptor, F > & | voc | ) | [inline] |
Assigns the given vocabulary to this by copying its data and removing all the data contained by this vocabulary before
voc |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save | ( | cv::FileStorage & | fs, | |
const std::string & | name = "vocabulary" | |||
) | const [inline, virtual] |
Saves the vocabulary to a file storage structure
fn | node in file storage |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::save | ( | const std::string & | filename | ) | const [inline] |
Saves the vocabulary into a file
filename |
double DBoW2::TemplatedVocabulary< TDescriptor, F >::score | ( | const BowVector & | a, | |
const BowVector & | b | |||
) | const [inline] |
Returns the score of two vectors
a | vector | |
b | vector |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setNodeWeights | ( | const vector< vector< TDescriptor > > & | features | ) | [inline, 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 |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setScoringType | ( | ScoringType | type | ) | [inline] |
Changes the scoring method
type | new scoring type |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::setWeightingType | ( | WeightingType | type | ) | [inline] |
Changes the weighting method
type | new weighting type |
unsigned int DBoW2::TemplatedVocabulary< TDescriptor, F >::size | ( | ) | const [inline, virtual] |
Returns the number of words in the vocabulary
int DBoW2::TemplatedVocabulary< TDescriptor, F >::stopWords | ( | double | minWeight | ) | [inline, 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.
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform | ( | const TDescriptor & | feature, | |
WordId & | id | |||
) | const [inline, protected, virtual] |
Returns the word id associated to a feature
feature | ||
id | (out) word id |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform | ( | const TDescriptor & | feature, | |
WordId & | id, | |||
WordValue & | weight, | |||
NodeId * | nid = NULL , |
|||
int | levelsup = 0 | |||
) | const [inline, protected, virtual] |
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 |
WordId DBoW2::TemplatedVocabulary< TDescriptor, F >::transform | ( | const TDescriptor & | feature | ) | const [inline, virtual] |
Transforms a single feature into a word (without weight)
feature |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform | ( | const std::vector< TDescriptor > & | features, | |
BowVector & | v, | |||
FeatureVector & | fv, | |||
int | levelsup | |||
) | const [inline, 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 |
void DBoW2::TemplatedVocabulary< TDescriptor, F >::transform | ( | const std::vector< TDescriptor > & | features, | |
BowVector & | v | |||
) | const [inline, virtual] |
Transforms a set of descriptores into a bow vector
features | ||
v | (out) bow vector of weighted words |
std::vector<Node*> DBoW2::TemplatedVocabulary< TDescriptor, F >::m_words [protected] |
Words of the vocabulary (tree leaves) this condition holds: m_words[wid]->word_id == wid