KeyError某些图像文件的索引均无。 svm中的问题,使用svm进行的糖尿病性视网膜病变分类

时间:2019-04-08 19:24:29

标签: python python-3.x pandas deep-learning svm

我已经检查了数据库和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)

这是错误消息

enter image description here

我希望图像能够成功加载,并且svm能够成功分类。

0 个答案:

没有答案