gpt4 book ai didi

python - Keras 深度学习简介 : 'X_train' is not defined?

转载 作者:行者123 更新时间:2023-11-30 09:40:19 26 4
gpt4 key购买 nike

所以我试图通过 Keras 更好地理解深度学习。我已经安装了 python、pip、tensorflow 和 jupyter Notebook 来运行它,但根据wardsdatascience.com 的“Keras 深度学习简介”中的以下示例,我已经遇到了错误。抱歉,如果这看起来很明显,但这是我第一次这样做,当您运行的第一个示例以某种方式出现错误时,很难判断问题所在。

给出的第一 block 代码是:

from keras.datasets import mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

这表明它正在使用 TensorFlow 后端。给出的第二个代码块是:

x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255

x_train = X_train.reshape(X_train.shape[0], 28, 28, 1)
x_test = X_test.reshape(X_test.shape[0], 28, 28, 1)

这会出现以下错误:

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-2-e2db9b91827f> in <module>
4 x_test /= 255
5
----> 6 x_train = X_train.reshape(X_train.shape[0], 28, 28, 1)
7 x_test = X_test.reshape(X_test.shape[0], 28, 28, 1)

NameError: name 'X_train' is not defined

这是这两部分的屏幕截图:enter image description here

我不明白在这种情况下如何无法定义 x_train,因为显然有一行指出“x_train = x_train.astype('float32')”

最佳答案

这实际上只是示例中的大小写问题。x_test 和 x_train 均更改为

x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)

非常感谢 oneturkmen 注意到这一点。

关于python - Keras 深度学习简介 : 'X_train' is not defined?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59161697/

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