Numpy - Python:ValueError:除了连接轴之外的所有输入数组维度必须完全匹配

时间:2017-09-06 10:04:56

标签: python numpy computer-vision feature-extraction scikit-image

我正在尝试使用skimage Lib从图像中提取HOG特征,然后训练他们到SVC

但我收到了错误

null
我用谷歌搜索它,发现功能阵列有多轴但不匹配,但我没有找到如何处理它...

Python代码:

Traceback (most recent call last):
  File ".\skimage-Hog.py", line 36, in <module>
    X = np.vstack( (car_features, notcar_features) ).astype(np.float64)
  File "C:\Program Files\Anaconda3\lib\site-packages\numpy\core\shape_base.py", line 230, in vstack
    return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: all the input array dimensions except for the concatenation axis must match exactly
import glob
import numpy as np 
from skimage.feature import hog
from skimage import color, exposure, io
from dataHandling import dataBase # lib to prepare images to work on it 

Positive, Negative = dataBase() 

def extract_feature(images):
    features = []
    for image in images:
        sourceImage = color.rgb2gray( io.imread(image) )
        hog_features = hog(sourceImage, orientations=8, pixels_per_cell=(8, 8), cells_per_block=(1, 1), visualise=False, feature_vector=True) 
        features.append(hog_features)
        print(image)

    return features
"""
car_features = extract_feature(Positive)
car_features.dump("car_features_RGB.p")

notcar_features = extract_feature(Negative)
notcar_features.dump("notcar_features_RGB.p")
"""
###

car_features = np.load("car_features_RGB.p") 
print("car_file Loaded" , len(car_features) )

notcar_features = np.load("notcar_features_RGB.p")
print("notcar_file Loaded ", len(notcar_features) )

### 
# Create an array stack of feature vectors
# Next line shows Error

任何建议

0 个答案:

没有答案