我已经检查了数据库和csv文件,并且错误消息中有指定文件的条目。我也尝试过删除错误图片,但即使这样也没有用。我是python的菜鸟。
path = "../train_resized/32x32/"
Files = []
Xlist = []
labels =[]
names = []
imlist = os.listdir(path)
#print imlist[0]
imlist = imlist[1:]
im = np.array(Image.open(imlist[0]) #open one image to get the size
m,n = im.shape[0:2]
df_label = pd.read_csv('trainLabels.csv' )
def get_labels(i):
l = i.split(os.path.sep)[-1].split(".")[0]
st1 = df_label.loc[[l]]
to_int = int(st1.values)
return to_int
def imagevector_label():
for file in os.listdir(path):
Files.append(file)
File = Files[1:]
immatrix = np.array([np.array(Image.open(path+'/'+file)).flatten() for file in File],'f')
for file in File:
names.append(file)
labels.append(get_labels(file))
return immatrix, np.array(labels)
img_vect, lab = imagevector_label()
from sklearn.model_selection import train_test_split
(trainRI, testRI, trainRL, testRL) = train_test_split(
img_vect, labels, test_size=0.25, random_state=42)
这是错误消息
我希望图像能够成功加载,并且svm能够成功分类。