【问题标题】:Data cardinality is ambiguous(Make sure all arrays contain the same number of samples)数据基数不明确(确保所有数组包含相同数量的样本)
【发布时间】:2022-11-11 10:29:34
【问题描述】:

我从 mnist 数据集得到我的数据集,

train_images = train_images.astype("float32")/255.0
test_images = test_images.astype("float32")/255.0

network.fit(train_images, train_labels, batch_size = 64, epochs = 10, verbose =2)
network.evaluate(test_images,test_labels, batch_size = 64, verbose=2)

我在训练期间遇到了这个错误

ValueError: Data cardinality is ambiguous:   x sizes: 10000   y sizes: 60000 Make sure all arrays contain the same number of samples .

谢谢

【问题讨论】:

  • 似乎 train_images 和 train_labels 的大小不同。你从哪里得到 train_labels 和 test_labels?您可以发布完整的代码以便我们重现吗?
  • 你能分享完整的代码来复制你的问题吗?

标签: python tensorflow keras


【解决方案1】:

这个错误背后的原因是,

“输入数据集 (x) 中的行数与标记的输出数据集 (y) 中的相应行不匹配”。 或者,将mnist 数据集拆分为训练和测试数据集时可能存在问题。

获取训练和测试数据集的输入和标记数据集的正确方法是:

mnist = tf.keras.datasets.fashion_mnist

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

print("Training dataset:", train_images.shape, train_labels.shape)
print("Testing dataset:", test_images.shape, test_labels.shape)

输出:(输入和输出集的行数应该相等)

Training dataset: (60000, 28, 28) (60000,)  
Testing dataset: (10000, 28, 28) (10000,)

请检查此附件gist 以供参考。

【讨论】:

    猜你喜欢
    • 2021-07-25
    • 2023-03-23
    • 2021-09-16
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    • 2021-07-09
    • 1970-01-01
    相关资源
    最近更新 更多