Loading MNIST

Gorgonia comes with an MNIST loader in its examples folder, and we can easily use this in our code by putting the following in our imports:

"gorgonia.org/gorgonia/examples/mnist"

Then, we can add the following lines to our code:

var inputs, targets tensor.Tensor
var err error
inputs, targets, err = mnist.Load(“train”, “./mnist/, “float64”)

This loads our images into a tensor named inputs and our labels into a tensor named targets (given that you have uncompressed the relevant files into an mnist folder, which should be where your executable is running).

In this example, we are loading the training set of MNIST, so it will produce a two-dimensional tensor with a size of 60,000 x 784 for the images, and another one with a size of 60,000 x 10 for the labels. The loader in Gorgonia will also helpfully rescale all the numbers to be between 0 and 1; we like small, normalized numbers when training our models.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.93.175