gpt4 book ai didi

python - reshape (60000, 28, 28, 1) 是什么意思?

转载 作者:行者123 更新时间:2023-12-01 00:32:24 25 4
gpt4 key购买 nike

我正在同时学习卷积网络和Python。

我的以下代码有问题:

import tensorflow as tf
print(tf.__version__)
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
training_images=training_images.reshape(60000, 28, 28, 1)

我不明白 reshape(60000, 28, 28, 1) 的含义。

60000 和 28 以及 28 和 1 是什么?

我将得到 60000 个 28 列 x 28 行的数组...而 1 是...

最佳答案

想一想,如果是 RGB,你会如何存储 60k 28 x 28 像素的图像?

对于每个像素,您需要 3 个标量(每个标量对应一个 channel ),因此它将是 60000x28x28x3

当图像为灰度时,您需要多少个 channel ?只有一个,所以它将是 60000x28x28x1

当然,如果是一个 channel ,则可以进一步简化为 60000x28x28,但我认为前一种方法更好,因为您明确提供了有关图像具有多少个 channel 的信息,并且看起来某些 ML 框架需要该信息才能正确操作。

关于python - reshape (60000, 28, 28, 1) 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58081284/

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