0
$\begingroup$

This is my approach

svm = cv2.ml.SVM_create()
svm.setType(cv2.ml.SVM_C_SVC)
svm.setKernel(cv2.ml.SVM_RBF)
svm.trainAuto(data["encodings"], cv2.ml.ROW_SAMPLE,data["names"])

where I get encodings using HOG and names from:

for (i, imagePath) in enumerate(imagePaths):
    # extract the person name from the image path
    print("[INFO] processing image {}/{}".format(i + 1, len(imagePaths)))
    name = imagePath.split(os.path.sep)[-2]

but when I train

'samples is not a numpy array, neither a scalar'

this error appears in the line:

svm.trainAuto(data["encodings"], cv2.ml.ROW_SAMPLE,data["names"])

I think I need to convert the names to a numpy array.

How can I do that?

$\endgroup$

2 Answers 2

1
$\begingroup$

It's hard to tell exactly what you're asking, and exactly what your data looks like. Nonetheless, I think you're asking how to convert a list to a numpy.array.

Try this:

np.asarray(data["names"])
$\endgroup$
0
$\begingroup$

That depends on the type you are converting it from.

As I currently do not have the information, I will assume the type of data is a pandas dataframe.

In that case you could use something like data["names"].values to convert your data to a numpy array.

$\endgroup$
1
  • $\begingroup$ name = imagePath.split(os.path.sep)[-2]-->this is how i get the name,it is a list $\endgroup$ Commented Sep 25, 2018 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.