Ask Your Question

Prithivi's profile - activity

2015-01-04 11:08:40 -0600 commented answer pyopencv_from and pyopencv_to for KeyPoint class

@berak - here is the issue and fix in the code posted.

traindata should be declared a numpy ndarray and NOT a list. So when the bow_extract is returning bowdescriptors it will be loaded into the traindata array one descriptor per index. The shape of the traindata ndarray should be x * y where x = number of images trained and y = number of features of bow_trainer.

code changes:

traindata = np.(shape=(x,y))  # in C++ they are using MAT type matrix
trainlabels = []                        # this can be list

traindata = np.float32(traindata)  #do this or svm.train(...) will throw floating point error
 :
svm.train(traindata, np.array(trainlabels))  #see no np.array for traindata !!

Thanks for the help. BOW for python works like a charm !!

2015-01-04 09:30:17 -0600 received badge  Supporter (source)
2015-01-04 09:29:55 -0600 commented answer pyopencv_from and pyopencv_to for KeyPoint class

@berak - Thanks for the advice. Sorry but here is what i see.

traindata is a list, of numpy.ndarrays and if i print it this what i see.

>>> traindata
[array([[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]], dtype=float32), array([[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]], dtype=float32)]

svm.train takes numpy arrays for both samples(train data) and response (train labels)

svm.train(np.array(traindata), np.array(trainlabels))

so if i print np.array(train data)

>>> np.array(traindata)
array([[[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]]], dtype=float32)

Any advices on this?

and if i use the above i still get the error

rror: (-5) train data must be floating-point matrix in function cvCheckTrainData
2015-01-04 09:26:12 -0600 answered a question pyopencv_from and pyopencv_to for KeyPoint class

@berak - Thanks for the advice. Sorry but here is what i see.

traindata is a list, of numpy.ndarrays and if i print it this what i see.

>>> traindata
[array([[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]], dtype=float32), array([[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]], dtype=float32)]

svm.train takes numpy arrays for both samples(train data) and response (train labels)

svm.train(np.array(traindata), np.array(trainlabels))

so if i print np.array(train data)

>>> np.array(traindata)
array([[[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]]], dtype=float32)

Any advices on this?

2015-01-04 08:20:06 -0600 commented answer pyopencv_from and pyopencv_to for KeyPoint class

@berak

Thanks for wrapping BOW in python.

I tried using the above code and the below line

svm.train(np.array(traindata), np.array(trainlabels))

Throws this error

   error: (-5) train data must be floating-point matrix in function cvCheckTrainData

here is what my train data (samples) look like (Apparently after doing some googling I did traindata = np.float32(traindata) and same for trainlabels)

>>> np.array(traindata)
array([[[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]]], dtype=float32)

here is what my train labels (responses) look like

>>> np.array(trainlabels)
array([ 1., -1.], dtype=float32)

Am i missing something, please point out what am I doing wrong.

2015-01-04 08:20:06 -0600 answered a question pyopencv_from and pyopencv_to for KeyPoint class

Thanks for wrapping BOW in python.

I tried using the above code and the below line

svm.train(np.array(traindata), np.array(trainlabels))

Throws this error

   error: (-5) train data must be floating-point matrix in function cvCheckTrainData

here is what my train data (samples) look like (Apparently after doing some googling I did traindata = np.float32(traindata) and same for trainlabels)

>>> np.array(traindata)
array([[[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.]]], dtype=float32)

here is what my train labels (responses) look like

>>> np.array(trainlabels)
array([ 1., -1.], dtype=float32)

Am i missing something, please point out what am I doing wrong.