Getting the data

The data for the MNIST data can be found in the repository for this chapter. In its original form, it's not in a standard image format. So, we will need to parse the data into an acceptable format.

The dataset comes in two parts: labels and images. So here are a couple of functions, designed to read and parse the MNIST file:

// Image holds the pixel intensities of an image.// 255 is foreground (black), 0 is background (white).type RawImage []byte// Label is a digit label in 0 to 9type Label uint8const numLabels = 10const pixelRange = 255const (  imageMagic = 0x00000803  labelMagic = 0x00000801  Width = 28  Height = 28)func readLabelFile(r io.Reader, e error) (labels []Label, err error) {  if e != nil {    return nil, e  } var magic, ...

Get Go Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.