[英]traceback when trying to set up the Michael Nielsen mnist network
I'm trying to set up a network for learning mnist digits as described by Michael Nielsen in his book ( http://neuralnetworksanddeeplearning.com/chap1.html#exercises_191892 ).我正在尝试建立一个用于学习 mnist 数字的网络,正如 Michael Nielsen 在他的书中所描述的那样 ( http://neuralnetworksanddeeplearning.com/chap1.html#exercises_191892 )。 However, when trying to import the mnist_loader into a Python3 shell, I get a traceback I can't make any sense of.
但是,当尝试将 mnist_loader 导入 Python3 shell 时,我得到了一个我无法理解的回溯。 Very greatful for any help!
非常感谢任何帮助!
>>> import mnist_loader
>>> training_data, validation_data, test_data = \
... mnist_loader.load_data_wrapper()
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/Users/xxx/Nielsen Network/src/mnist_loader.py", line 68, in load_data_wrapper
tr_d, va_d, te_d = load_data()
File "/Users/xxx/Nielsen Network/src/mnist_loader.py", line 43, in load_data
training_data, validation_data, test_data = cpickle.load(f)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128)
this ist the mnist_loader.py:这是 mnist_loader.py:
import _pickle as cpickle
import gzip
# Third-party libraries
import numpy as np
def load_data():
"""Return the MNIST data as a tuple containing the training data,
the validation data, and the test data.
The ``training_data`` is returned as a tuple with two entries.
The first entry contains the actual training images. This is a
numpy ndarray with 50,000 entries. Each entry is, in turn, a
numpy ndarray with 784 values, representing the 28 * 28 = 784
pixels in a single MNIST image.
The second entry in the ``training_data`` tuple is a numpy ndarray
containing 50,000 entries. Those entries are just the digit
values (0...9) for the corresponding images contained in the first
entry of the tuple.
The ``validation_data`` and ``test_data`` are similar, except
each contains only 10,000 images.
This is a nice data format, but for use in neural networks it's
helpful to modify the format of the ``training_data`` a little.
That's done in the wrapper function ``load_data_wrapper()``, see
below.
"""
f = gzip.open('../data/mnist.pkl.gz', 'rb')
training_data, validation_data, test_data = cpickle.load(f)
f.close()
return (training_data, validation_data, test_data)
def load_data_wrapper():
"""Return a tuple containing ``(training_data, validation_data,
test_data)``. Based on ``load_data``, but the format is more
convenient for use in our implementation of neural networks.
In particular, ``training_data`` is a list containing 50,000
2-tuples ``(x, y)``. ``x`` is a 784-dimensional numpy.ndarray
containing the input image. ``y`` is a 10-dimensional
numpy.ndarray representing the unit vector corresponding to the
correct digit for ``x``.
``validation_data`` and ``test_data`` are lists containing 10,000
2-tuples ``(x, y)``. In each case, ``x`` is a 784-dimensional
numpy.ndarry containing the input image, and ``y`` is the
corresponding classification, i.e., the digit values (integers)
corresponding to ``x``.
Obviously, this means we're using slightly different formats for
the training data and the validation / test data. These formats
turn out to be the most convenient for use in our neural network
code."""
tr_d, va_d, te_d = load_data()
training_inputs = [np.reshape(x, (784, 1)) for x in tr_d[0]]
training_results = [vectorized_result(y) for y in tr_d[1]]
training_data = zip(training_inputs, training_results)
validation_inputs = [np.reshape(x, (784, 1)) for x in va_d[0]]
validation_data = zip(validation_inputs, va_d[1])
test_inputs = [np.reshape(x, (784, 1)) for x in te_d[0]]
test_data = zip(test_inputs, te_d[1])
return (training_data, validation_data, test_data)
def vectorized_result(j):
"""Return a 10-dimensional unit vector with a 1.0 in the jth
position and zeroes elsewhere. This is used to convert a digit
(0...9) into a corresponding desired output from the neural
network."""
e = np.zeros((10, 1))
e[j] = 1.0
return e
Looks like you're running Python 3 version.看起来您正在运行 Python 3 版本。 If I try it with Python3 I get the same error.
如果我用 Python3 尝试它,我会得到同样的错误。 As stated in the README it only supports Python 2.6 or 2.7.
如README中所述,它仅支持 Python 2.6 或 2.7。 If you cannot run it with Python 2 try this other repository below mentioned in the same README that supports Python 3
如果您无法使用 Python 2 运行它,请尝试下面在支持 Python 3 的同一个 README 中提到的另一个存储库
MichalDanielDobrzanski/DeepLearningPythonMichalDanielDobrzanski/DeepLearningPython
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.