基于数据集类创建数据集时出错CIFAR10



>我需要创建 2 个数据集,其中一个数据集的类从 0 到 4,另一个数据集的类从 5 到 9CIFAR10,但我收到此错误:"boolean index did not match indexed array along dimension 1; dimension is 32 but corresponding boolean dimension is 1"

这是我到目前为止尝试过的

import keras
from keras.datasets import cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print('x_train shape:', x_train.shape)
x_train shape: (50000, 32, 32, 3)
Getting error at this point
x_train = x_train[y_train < 5]

打印出 y_train.shape 给出 (50000, 1(。若要使用 y_train正确索引x_train的第一个维度,必须去除第二个维度。

x_train = x_train[y_train[:, 0] < 5]

[:, 0]表示法表示返回沿第一维的所有元素,但仅返回第二维上的第一个元素。

x_train.shape现在给出(25000,32,32,3(。

最新更新