简体   繁体   English

Keras 深度学习简介:'X_train' 未定义?

[英]Introduction to Deep Learning with Keras: 'X_train' is not defined?

So I'm trying to better understand deep learning through Keras.所以我试图通过 Keras 更好地理解深度学习。 I've installed python, pip, tensorflow, and jupyter notebook to run this with, but based on the following example from "Introduction to Deep Learning with Keras" from towardsdatascience.com, I've already run into an error.我已经安装了 python、pip、tensorflow 和 jupyter notebook 来运行它,但根据来自towardsdatascience.com 的“Introduction to Deep Learning with Keras”中的以下示例,我已经遇到了错误。 Sorry if this seems very obvious, but this is the first time I've done something with this, and it's difficult to gauge the problem when the very first example you've ever ran somehow has an error in it.对不起,如果这看起来很明显,但这是我第一次用这个做一些事情,当你运行的第一个例子以某种方式有错误时很难判断问题。

The first block of code given is:给出的第一个代码块是:

from keras.datasets import mnist

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

Which states that it is using TensorFlow backend.这表明它正在使用 TensorFlow 后端。 The second block of code given is:给出的第二个代码块是:

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)

Which gives the following error:这给出了以下错误:

---------------------------------------------------------------------------
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

Here's a screenshot of these two parts:下面是这两部分的截图: 在此处输入图片说明

I don't see how x_train couldn't be defined in this situation however, as there's clearly a line that states "x_train = x_train.astype('float32')"但是,我不明白在这种情况下如何无法定义 x_train,因为显然有一行表示“x_train = x_train.astype('float32')”

This was in fact just a casing issue in the example.这实际上只是示例中的大小写问题。 x_test and x_train were both changed to 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)

Big thanks to oneturkmen for noting this.非常感谢 oneturkmen 注意到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM