Comment on page

Bag of Words

DBoW Library

The library is composed of two main classes: Vocabulary and Database. The former is trained offline with numerous images, whereas the latter can be established/expanded online. Both structures can be saved in binary or text format.


Words in the vocabulary and in bag-of-words vectors are weighted. There are four weighting measures implemented to set a word weight wi:
  • Term frequency (tf):
    w_i = \frac{n_{id}}{n_d}
    : number of occurrences of word i in document d,
    : number of words in document d.
  • Inverse document frequency (idf):
    w_i = log(\frac{N}{N_i})
    : number of documents,
    : number of documents containing word i.
  • Term frequency -- inverse document frequency (tf-idf):
    w_i = \frac{n_{id}}{n_d} log(\frac{N}{N_i}
  • Binary:
    w_i = 1 if word i is present; 0 otherwise
DBow calculates N and Ni according to the number of images provided when the vocabulary is created. These values are not changed and are independent of how many entries a Database object contains.


A score is calculated when two vectors are compared by means of a Vocabulary or when a Database is queried. These are the metrics implemented to calculate the score s between two vectors v and w (from now on, v* and w* denote vectors normalized with the L1-norm):
The default configuration when creating a vocabulary is tf-idf, L1-norm.