Ask Your Question
0

SVM Train error: (-215:Assertion failed) problem

asked 2018-11-18 23:33:33 -0600

cnrblm gravatar image

image description

Hi. I want to use svm for classification. I created train and label data. When i ran svm.train method, I see these errors

OpenCV(3.4.2) /io/opencv/modules/ml/src/svm.cpp:1381: error: (-215:Assertion failed) _samples.type() == 5 in function 'do_train'

svm=cv2.ml.SVM_create()
svm.setKernel(cv2.ml.SVM_LINEAR)
svm.setType(cv2.ml.SVM_C_SVC)
svm.train(X, cv2.ml.ROW_SAMPLE, y)

Any suggestions. Thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-11-19 01:01:48 -0600

berak gravatar image

updated 2018-11-19 01:09:21 -0600

it wants float32 for the data, and int32 for the labels, int64 is wrong for both x and y. you also need numpy arrays, not plain lists

try:

X = np.asarray(X, np.float32)
y = np.asarray(y, np.int32)
svm.train(X, cv2.ml.ROW_SAMPLE, y)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-11-18 23:33:33 -0600

Seen: 395 times

Last updated: Nov 19 '18