gpt4 book ai didi

python - 如何从 Keras 提供的 MNIST 数据集中仅选择特定数量的样本?

转载 作者:太空宇宙 更新时间:2023-11-03 15:34:43 24 4
gpt4 key购买 nike

我目前正在使用 Keras 在 MNIST 数据集上训练卷积神经网络。我正在使用格式加载数据集

(X_train, Y_train), (X_test, Y_test) = mnist.load_data()

但为了减少对所有数据的迭代,我只想为 X_train 选择 0-9 类中的前 10000 个样本,并且类似地从 Y_train 中选择。我怎样才能做到这一点?

最佳答案

MNIST 数据集表示它返回:

Return:

2 tuples:
X_train, X_test: uint8 array of grayscale image data with shape (nb_samples, 28, 28).
y_train, y_test: uint8 array of digit labels (integers in range 0-9) with shape (nb_samples,).

所以你需要只切片你想要保留的部分。我相信 pandas/numpy 的语法类似于:

X_train = X_train[:10000,:,:]
X_test = X_test[:10000,:,:]
y_train = y_train[:10000]
y_test = y_test[:10000]

关于python - 如何从 Keras 提供的 MNIST 数据集中仅选择特定数量的样本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42617693/

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