0

I have an array of size 301 x 4096, for which I want to calculate the VLAD vector.

I tried to do the quantization using

center, assignments = vlfeat.vl_kmeans(data,8)

but this returns

ValueError: too many values to unpack

If I change number of clusters from 8 to 2, it works. I've also tried other numbers, but all of them returned the same ValueError. Except, when setting it to 1, it returns

ValueError: need more than 1 value to unpack

Could it be that it has to do with the number of samples in my data?

hbaderts
  • 14,136
  • 4
  • 41
  • 48
ytrewq
  • 3,670
  • 9
  • 42
  • 71
  • 1
    It has to do with the number of items returned by the function. If it is more than 2, you'll get `too many values to unpack`, when its less than two, you get `more than 1 value to unpack`. – Burhan Khalid Feb 11 '16 at 11:28
  • + [see this](https://github.com/dougalsutherland/vlfeat-ctypes/blob/master/vlfeat/kmeans.py#L126). It returns a named tuple, which is single object with your stuff in it. – mehmetminanc Feb 11 '16 at 11:36
  • @BurhanKhalid meaning it should be always two? Then how do I specify the other number of clusters? – ytrewq Feb 12 '16 at 06:38

1 Answers1

0

The sources of this inofficial Python interface to VLFeat is available on Github.

The vl_kmeans function by default only returns the centers, so there is only one value to unpack:

import numpy as np
import vlfeat
x = np.random.rand(10, 8)
centers = vlfeat.vl_kmeans(x, 3)

The resulting centers array will have the shape (3, 8), i.e. a 8-dimensional point for each of the 3 centers.

If you want to obtain the assignments for each of the inputs, you have to pass the option quantize to the vl_kmeans function. Then, the function does return both centers and assignment, and this works as expected:

centers, assignments = vlfeat.vl_kmeans(x, 3, quantize=True)
hbaderts
  • 14,136
  • 4
  • 41
  • 48