我是python的新手,但我想将这个函数向量化。有可能吗?
from skimage.feature import hog
import numpy as np
def hog_features(X):
"""
Extract HOG features from input images
Args:
X: Data matrix of shape [num_train, 577]
Returns:
hogs: Extracted hog features
"""
hog_list = []
for i in range(X.shape[0]):
t = hog(np.reshape(X[i][1:],[24,24],order='F'),orientations=8, pixels_per_cell=(2, 2),
cells_per_block=(1, 1), visualize=False, multichannel=False,feature_vector = True)
np.append(1, t)
hog_list.append(t)
hogs = np.stack(hog_list,axis=0)
return hogs
我尝试过这种方法,但它不起作用,我认为是因为我必须指定输入参数的签名。但是我什至不知道签名是什么。其中X是(m,n)numpy.ndarray
hog_v = np.vectorize(hog_features,signature='X')
感谢您的帮助:)