简体   繁体   中英

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

So I'm trying to better understand deep learning through 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. 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. 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')"

This was in fact just a casing issue in the example. x_test and x_train were both changed to

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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