我按照本教程创建了一个简单的图像分类:
https://blog.hyperiondev.com/index.php/2019/02/18/machine-learning/
在训练之前,我们对数据集中的图片进行矢量化,如下所示:
train_data = scipy.io.loadmat('extra_32x32.mat')
# extract the images and labels from the dictionary object
X = train_data['X']
y = train_data['y']
# example: view an image (e.g. 25) and print its corresponding label
img_index = 25
plt.imshow(X[:,:,:,img_index])
plt.show()
print(y[img_index])
X = X.reshape(X.shape[0]*X.shape[1]*X.shape[2],X.shape[3]).T
y = y.reshape(y.shape[0],)
X, y = shuffle(X, y, random_state=42)
完成训练后,我想上传另一张图片(不在数据集中)并将其传递给分类器以检查它是否被预测(连同它的准确度分数)
但是我怎么能通过图片呢?我试过这个:
jpgfile = Image.open("63.jpg")
value = clf.predict(jpgfile)
并得到一个错误:
Found array with dim 3. Estimator expected <= 2.
那么,由于我没有单独的 x,y 值,因此如何对其进行矢量化。