我正在制作一个支持向量机分类器来分类图像。该程序使用Google,并将文件上传到Google中。图像的形状是torch.Size([32, 3, 224, 224])。
我就是这样分割数据集的,
images = (images.numpy())
labels = (labels.numpy())
X_train, X_test, y_train, y_test = train_test_split(images, labels, test_size=0.3, random_state=42)在对列车数据和试验数据进行分割后,X_train和X_test的新形态为(22, 3, 224, 224)和(10, 3, 224, 224)。现在,当我试图解决这个问题时,就会出现问题。
# Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)
#fit to the trainin data
classifier.fit(X_train,y_train)
----> 3 classifier.fit(X_train,y_train)
537 if not allow_nd and array.ndim >= 3:
538 raise ValueError("Found array with dim %d. %s expected <= 2."
--> 539 % (array.ndim, estimator_name))
540 if force_all_finite:
541 _assert_all_finite(array,ValueError:找到带有dim 4的数组。估计器期望<= 2。
我有4个图像类,我希望支持向量机分类器训练模型,以前我用CNN和传输学习。我读过一些帖子,在这里我可能要重塑它。你能帮我解决这个问题吗?谢谢你的帮助。
发布于 2019-07-24 18:06:18
当前,您的输入数据(batch size, channels, height, width)有4个维度,您需要将图像平平为二维(number of images, channels* height* width)。
X_train = X_train.reshape(22,3*224*224)
X_test = X_test.reshape(10,3*224*224)https://stackoverflow.com/questions/57187680
复制相似问题