[英]Numpy array declaration error
我編寫了以下代碼以從圖像中提取特征。 一旦從featex函數中提取出特征向量,就需要將其附加到一個大型特征2D數組中,該數組包含用於訓練的所有圖像的特征。 代碼如下:
for dirs, path, files in os.walk("wallet_training/"):
for filename in files:
f=os.path.join("wallet_training",filename)
I=Image.open("wallet_training/1(1).jpeg")
I=imresize(I,(256,256))
p=featex(I)
features=np.vstack([features],[p])
print features.shape
它給出以下錯誤:
NameError: name 'features' is not defined
有人可以幫我為什么會出現此錯誤,因為據我所知,python中的變量不需要事先定義。
先感謝您。
正如其他用戶在評論中建議的那樣,您需要聲明features
。
另外,我建議您使用Python列表添加數據,然后轉換為numpy數組:
features = [];
for dirs, path, files in os.walk("wallet_training/"):
for filename in files:
f=os.path.join("wallet_training",filename)
I=Image.open("wallet_training/1(1).jpeg")
I=imresize(I,(256,256))
p=featex(I)
features.append(p) #'features' is a Python list
features = np.array(features)#Now 'features' is an array
print features.shape
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.