Ask Your Question
0

Issue kernel_type no attribute called cv2.SVM_LINEAR

asked 2016-02-25 09:25:30 -0600

Hello, I am using the version 3.0.0 of OpenCV with Python version 2.7. I would like to use the SVM algorithm like below:

svm_params = dict( kernel_type=cv2.SVM_LINEAR, svm_type=cv2.SVM_C_SVC, C=1 ) svm_model = cv2.SVM() svm_model.train(training_set, response, params=svm_params)

But there is no attribute called 'SVM_LINEAR' Thanks in advance

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-02-25 09:32:49 -0600

berak gravatar image

updated 2016-02-25 09:37:08 -0600

the syntax has changed a bit from 2.4. to 3:

# it's all in a cv2.ml submodule now
help(cv2.ml)

svm = cv2.ml.SVM_create() #you need a 'create' function for all ml classes
svm.setKernel(cv2.ml.SVM_LINEAR) #getters & setters for all params
svm.setType(cv2.ml.SVM_C_SVC) 

svm.train(np.array(traindata), cv2.ml.ROW_SAMPLE, np.array(trainlabels))
edit flag offensive delete link more

Comments

also, if you can, update to 3.1, the 3.0 version cannot load serialized svm files (bug)

berak gravatar imageberak ( 2016-02-25 09:38:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-25 09:25:30 -0600

Seen: 969 times

Last updated: Feb 25 '16