1g2dZddlZddlZddlZdZdZdZy)a mnist_loader ~~~~~~~~~~~~ A library to load the MNIST image data. For details of the data structures that are returned, see the doc strings for ``load_data`` and ``load_data_wrapper``. In practice, ``load_data_wrapper`` is the function usually called by our neural network code. Nctjdd}tj|}d|_|j \}}}|j |||fS)aReturn the MNIST data as a tuple containing the training data, the validation data, and the test data. print(load_data_wrapper()[0]) 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. z../data/mnist.pkl.gzrblatin1)gzipopenpickle _Unpicklerencodingloadclose)fu training_datavalidation_data test_datas q/Users/aayushbajaj/Documents/new-site/static/code/10khrs-ai-ml-dl/learning/nielsen-dl/authors/src/mnist_loader.py load_datarsT2 ($/A!AAJ01-M?IGGI ?I 66ct\}}}|dDcgc]}tj|d}}|dDcgc] }t|}}t t ||}|dDcgc]}tj|d}}t t ||d} |dDcgc]}tj|d} }t t | |d} || | fScc}wcc}wcc}wcc}w)aReturn 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.r)ir)rnpreshapevectorized_resultlistzip) tr_dva_dte_dxtraining_inputsytraining_resultsrvalidation_inputsr test_inputsrs rload_data_wrapperr%3s*!{D$8g)!,g>_.>?@M:>q'B'QAx0'B30$q':;O48GBr.s' 7@7> r