SVM与SKLearn& OpenCV的

时间:2016-11-17 16:06:15

标签: python opencv scikit-learn svm

我正在尝试使用SVM预测图像上显示的情绪。但是,当我运行我的代码时,我收到如下警告,我的预测没有显示:

弃用警告:传递1d数组,因为数据在0.17中已弃用,并且会在0.19中提升ValueError。如果数据具有单个要素,则使用X.reshape(-1,1)重新整形数据;如果包含单个样本,则使用X.reshape(1,-1)重新整形数据。   DeprecationWarning)

这是培训和测试的代码:

    emotions = ["anger", "neutral"]
    def make_sets(emotions):
    training_data = []
    training_labels = []

    for emotion in emotions:
        training = glob.glob("try here\\%s\\*" %emotion)
        for item in training:
            image = cv2.imread(item) 
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            training_data.append(gray.ravel())
            training_labels.append(emotions.index(emotion))
    return training_data, training_labels

    x,y = make_sets(emotions)
    new_x = np.asarray(x)
new_x.flatten()
new_y = np.asarray(y)
clf = svm.SVC(kernel='linear', C=1.0)
clf.fit(new_x,new_y)
new_image = cv2.imread('test.jpg')
gray_img = cv2.cvtColor(new_image, cv2.COLOR_BGR2GRAY)
clf.predict(gray_img.ravel())

0 个答案:

没有答案