GoMNIST

package module
v0.0.0-...-f6acf86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

README

GoMNIST

GoMNIST is a Go driver for reading Yann LeCun's MNIST dataset of handwritten digits

The MNIST dataset is included. It is a copy from Yann LeCun's MNIST page.

How to use

Install the packages:

% go get github.com/petar/GoMNIST

Import them in your code as

% import "github.com/petar/GoMNIST"

Load the MNIST training and testing data sets into memory using

train, test, err := Load("./data")
if err != nil {
	…
}

Sweep through the samples

sweeper := train.Sweep()
for {
	image, label, present := sweeper.Next()
	if !present {
		break
	}
	…
}

You can also have random access to the sets, using the methods of Set.

Author

My homepage is Petar Maymounkov. Follow me on Twitter at @maymounkov.

Documentation

Index

Constants

View Source
const (
	Width  = 28
	Height = 28
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Label

type Label uint8

Label is a digit label in 0 to 9

func ReadLabelFile

func ReadLabelFile(name string) (labels []Label, err error)

ReadLabelFile opens the named label file (training or test), parses it and returns all labels in order.

type RawImage

type RawImage []byte

Image holds the pixel intensities of an image. 255 is foreground (black), 0 is background (white).

func ReadImageFile

func ReadImageFile(name string) (rows, cols int, imgs []RawImage, err error)

ReadImageFile opens the named image file (training or test), parses it and returns all images in order.

func (RawImage) At

func (img RawImage) At(x, y int) color.Color

func (RawImage) Bounds

func (img RawImage) Bounds() image.Rectangle

func (RawImage) ColorModel

func (img RawImage) ColorModel() color.Model

type Set

type Set struct {
	NRow   int
	NCol   int
	Images []RawImage
	Labels []Label
}

Set represents a data set of image-label pairs held in memory

func Load

func Load(dir string) (train, test *Set, err error)

Load reads both the training and the testing MNIST data sets, given a local directory dir, containing the MNIST distribution files.

func ReadSet

func ReadSet(iname, lname string) (set *Set, err error)

ReadSet reads a set from the images file iname and the corresponding labels file lname

func (*Set) Count

func (s *Set) Count() int

Count returns the number of points available in the data set

func (*Set) Get

func (s *Set) Get(i int) (RawImage, Label)

Get returns the i-th image and its corresponding label

func (*Set) Sweep

func (s *Set) Sweep() *Sweeper

Sweep creates a new sweep iterator over the data set

type Sweeper

type Sweeper struct {
	// contains filtered or unexported fields
}

Sweeper is an iterator over the points in a data set

func (*Sweeper) Next

func (sw *Sweeper) Next() (image RawImage, label Label, present bool)

Next returns the next image and its label in the data set. If the end is reached, present is set to false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL