Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何解决';ValueError:找到具有dim 4的数组。预计估计值<;=2.';?_Image_Machine Learning_Scikit Learn_Svm - Fatal编程技术网

Image 如何解决';ValueError:找到具有dim 4的数组。预计估计值<;=2.';?

Image 如何解决';ValueError:找到具有dim 4的数组。预计估计值<;=2.';?,image,machine-learning,scikit-learn,svm,Image,Machine Learning,Scikit Learn,Svm,我正在做一个SVM分类器来分类图像。该程序使用Google collab,文件上传到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)

我正在做一个SVM分类器来分类图像。该程序使用Google collab,文件上传到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_列车和X_试验的新形状为
(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,
#创建分类器:支持向量分类器
分类器=svm.SVC(伽马=0.001)
#适合列车入站数据
分类器。配合(X_系列,y_系列)
---->3.装配(X_系列、y_系列)
537如果不允许\u nd和array.ndim>=3:

538 raise VALUE ERROR(“找到的数组的尺寸应为%d.%s当前,您的输入数据有4维
(批量大小、通道、高度、宽度)
您需要将图像展平到二维
(图像数量、通道*高度*宽度)


希望这有帮助!

谢谢。我现在可以做了。
X_train = X_train.reshape(22,3*224*224)
X_test = X_test.reshape(10,3*224*224)