0
我目前正與以下:與OpenCV的2.4.11打開圖像作爲數據集用於sklearn
- 的Python 2.7
- OpenCV的2.4.11
- Sklearn 0.16.1
並正在使用following tutorial。
我的目標是加載我自己的數據集,而不是使用預定義的數據集。我試圖通過執行以下操作來實現:
import numpy as np
import cv2
import os
from matplotlib import pyplot as plt
from os import listdir
from os.path import isfile, join
from sklearn import datasets
from sklearn import svm
digits = datasets.load_digits()
imageFolderPath ='C:/PathToFolderContainingMyImages/'
# Getting all the paths for each image
individualImagePaths = [ imageFolderPath + f for f in listdir(imageFolderPath) if isfile(join(imageFolderPath,f))]
individualImagePaths = sorted(individualImagePaths)
logos = []
logoLabels = []
for x in individualImagePaths:
filename = os.path.basename(x).split(" ")
filename = filename[0]
logos.append(np.array(cv2.imread(x,0)))
logoLabels.append(filename)
logos = np.asarray(logos)
logoLabels = np.asarray(logoLabels)
print type(logos)
print type(logoLabels)
print logos[0]
print logoLabels[0]
print type(digits.images)
print type(digits.target)
print digits.images[0]
print digits.target[0]
clf = svm.SVC(gamma=0.001, C=100.)
clf.fit(logos[:-1], logoLabels[:-1])
運行此腳本時,我收到以下錯誤:
array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: setting an array element with a sequence.
我的圖片命名爲:
「 1(1).png「爲1位數的圖像
」2(1).png「爲2位數的圖像
「2(2)。PNG」 爲一個圖像是一個2位數的
print type(logos)
print type(logoLabels)
print logos[0]
print logoLabels[0]
回報:
<type 'numpy.ndarray'>
<type 'numpy.ndarray'>
[[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
...,
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]
[255 255 255 ..., 255 255 255]]
0
print type(digits.images)
print type(digits.target)
print digits.images[0]
print digits.target[0]
回報:
<type 'numpy.ndarray'>
<type 'numpy.ndarray'>
[[ 0. 0. 5. 13. 9. 1. 0. 0.]
[ 0. 0. 13. 15. 10. 15. 5. 0.]
[ 0. 3. 15. 2. 0. 11. 8. 0.]
[ 0. 4. 12. 0. 0. 8. 8. 0.]
[ 0. 5. 8. 0. 0. 9. 8. 0.]
[ 0. 4. 11. 0. 1. 12. 7. 0.]
[ 0. 2. 14. 5. 10. 12. 0. 0.]
[ 0. 0. 6. 13. 10. 0. 0. 0.]]
0
有關如何創建/加載我的owndata集並使用sklearn fit
函數的數據集的任何想法?