【发布时间】:2019-12-03 16:44:50
【问题描述】:
所以我试图通过 Keras 更好地理解深度学习。我已经安装了 python、pip、tensorflow 和 jupyter notebook 来运行它,但是基于来自面向datascience.com 的“Keras 深度学习简介”中的以下示例,我已经遇到了一个错误。对不起,如果这看起来很明显,但这是我第一次用这个做一些事情,当你运行的第一个示例以某种方式出现错误时,很难判断问题所在。
给出的第一段代码是:
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
我不明白如何在这种情况下无法定义 x_train,因为显然有一行声明“x_train = x_train.astype('float32')”
【问题讨论】:
-
它应该是小写的,即
x_train而不是X_train -
解决了。谢谢。
标签: python tensorflow machine-learning keras jupyter-notebook