gpt4 book ai didi

keras - 仅选择特定类别的 CIFAR-10

转载 作者:行者123 更新时间:2023-12-03 19:36:38 32 4
gpt4 key购买 nike

我想使用 CIFAR-10 数据集,但我只想要 Frog 、狗、猫、马和鸟类,到目前为止我已经使用了以下代码:

  # Plot ad hoc CIFAR10 instances
from keras.datasets import cifar10
from matplotlib import pyplot
from scipy.misc import toimage
# load data
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
# create a grid of 3x3 images
for i in range(0, 9):
pyplot.subplot(330 + 1 + i)
pyplot.imshow(toimage(X_train[i]))
# show the plot
pyplot.show()

cifar10.load_data() 函数加载整个数据,我可以只获取所需的类吗?

最佳答案

(X_train, y_train), (X_test, y_test) = tf.keras.datasets.cifar10.load_data()

其中包含 10 个类的所有样本

选择关于类的索引
index = np.where(y_train == 0)
X_train = X_train[indices]
y_train = y_train[indices]

这给出了所有第 0 个索引样本

关于keras - 仅选择特定类别的 CIFAR-10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48213663/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com