VLFeat: ValueError for certain number of clusters in vl_kmeans

146 Views Asked by At

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?

1

There are 1 best solutions below

0
hbaderts On

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)