我正试图建立一个学习mnist数字的网络,正如迈克尔·尼尔森在他的书(http://neuralnetworksanddeeplearning.com/chap1.html#exercises_191892)中所描述的那样.然而,当try 将mnist\u加载程序导入到Python3 shell中时,我得到了一个无法理解的回溯.非常感谢您的帮助!

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

这是list\u加载程序.p:

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

推荐答案

看起来您正在运行Python 3版本.如果我用Python3try ,我会得到同样的错误.如README中所述,它只支持Python 2.6或2.7.如果无法使用Python 2运行它,请try 下面在支持Python 3的自述文件中提到的其他存储库

MichalDanielDobrzanski/DeepLearningPython

Python相关问答推荐

2维数组9x9,不使用numpy.数组(MutableSequence的子类)

难以在Manim中正确定位对象

Python json.转储包含一些UTF-8字符的二元组,要么失败,要么转换它们.我希望编码字符按原样保留

输出中带有南的亚麻神经网络

在线条上绘制表面

用合并列替换现有列并重命名

两个pandas的平均值按元素的结果串接元素.为什么?

Python,Fitting into a System of Equations

迭代嵌套字典的值

给定高度约束的旋转角解析求解

Python逻辑操作作为Pandas中的条件

Maya Python脚本将纹理应用于所有对象,而不是选定对象

LocaleError:模块keras._' tf_keras. keras没有属性__internal_'''

如何在两列上groupBy,并使用pyspark计算每个分组列的平均总价值

Pandas:填充行并删除重复项,但保留不同的值

如何在一组行中找到循环?

Python如何导入类的实例

根据过滤后的牛郎星图表中的数据计算新系列

将鼠标悬停在海运`pairplot`的批注/高亮显示上

如何批量训练样本大小为奇数的神经网络?