我在trainpath檔案夾中有一個影像串列作為我的資料集。在 trainpath 檔案夾下,有 2 個檔案夾,以類名(0 和 1)命名。在每個檔案夾下,都有影像資料。我嘗試使用該資料集創建訓練資料串列。
code = {'distracted':0 ,'not-distracted':1}
X_train = []
y_train = []
for folder in os.listdir(trainpath) :
files = gb.glob(pathname= str( trainpath '//' folder '/*.jpg'))
for file in files:
image = cv2.imread(file)
image_array = cv2.resize(image , (s,s))
X_train.append(list(image_array))
y_train.append(code[folder])
但是,我得到了這個錯誤:
KeyError Traceback (most recent call last)
<ipython-input-74-5016fe834a0a> in <module>()
7 image_array = cv2.resize(image , (s,s))
8 X_train.append(list(image_array))
----> 9 y_train.append(code[folder])
KeyError: '1'
uj5u.com熱心網友回復:
您需要將檔案夾名稱作為鍵,并將空串列作為值:
code = {'0':0 ,'1':1}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/493558.html
上一篇:部分切除的畫中畫
下一篇:CSS更改影像容器中的背景顏色
