python [Bag of Visual Words] #python

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [Bag of Visual Words] #python相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import scipy.cluster.vq as vq
from sklearn.datasets import load_digits
from sklearn.cross_validation import train_test_split


def main():
    digits = load_digits()
    print digits.data.shape # (1797, 64)

    # split digits data
    X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target)

    # computing the visual words
    K = int(np.sqrt(digits.data.shape[0]/2))
    codebook, distortion = vq.kmeans(X_train, K)
    print codebook

    # computing the histogram of visual words
    code, dist = vq.vq(X_test, codebook)
    vw_hist, bin_edges = np.histogram(code,
                                      bins=codebook.shape[0],
                                      normed=True)
    print vw_hist

if __name__ == '__main__':
    main()

以上是关于python [Bag of Visual Words] #python的主要内容,如果未能解决你的问题,请参考以下文章

Bag of features:图像检索

kaggle实战之 bag of words meet bag of poopcorn

Bag of mice(概率DP)

视觉SLAM之词袋(bag of words) 模型与K-means聚类算法浅析

词袋模型(bag of words)构建实战

bag of feature