36ml.mnist Module

36.1Overview

The ml.mnist module provides measures to read image database of handwritten digit called MNIST. MNIST data files are avaiable in: http://yann.lecun.com/exdb/mnist/.

The database consists of the following files:

  • train-images-idx3-ubyte.gz .. training set images
  • train-labels-idx1-ubyte.gz .. training set labels
  • t10k-images-idx3-ubyte.gz .. test set images
  • t10k-labels-idx1-ubyte.gz .. test set labels

36.2ml.mnist.dbpair Structure

36.2.1Constructor

mnist.dbpair(imageset:mnist.imageset, labelset:mnist.labelset) {block?}

36.2.2Property

A ml.mnist.dbpair instance has the following properties:

Property Type R/W Explanation
imageset ml.mnist.imageset R
labelset ml.mnist.labelset R

36.3ml.mnist.database Class

36.3.1Constructor

mnist.database(dirname:string) {block?}
Reads MNIST database files in a directory specified by dirname and returns a ml.mnist.database instance.

36.3.2Property

A ml.mnist.database instance has the following properties:

Property Type R/W Explanation
test ml.mnist.dbpair R
train ml.mnist.dbpair R

36.4ml.mnist.imageset Class

36.4.1Constructor

mnist.imageset(stream:stream):map {block?}

Reads MNIST image set file from the specified stream and returns a ml.mnist.imageset instance.

If block is specified, it would be evaluated with a block parameter |stream:stream|, where stream is the created instance. In this case, the block's result would become the function's returned value.

36.4.2Property

A ml.mnist.imageset instance has the following properties:

mnist.imageset#ncolsnumber [read-only]
Column size of each image.
mnist.imageset#nimagesnumber [read-only]
Number of labels in the database.
mnist.imageset#nrowsnumber [read-only]
Row size of each image.

36.4.3Method

mnist.imageset#toarray(shape?:symbol, elemtype?:symbol, normalize?:symbol):map {block?}

Creates an array instance from the MNIST image set.

Arguments:

  • shape .. element shape that takes `flat or `matrix. Default is `flat.
  • elemtype .. element type of created array that takes `uint8, `half, `float or `double. Default is `float.
  • normalize .. specifies whether it maps element values of [0, 255] into a range of [0, 1]. Default is true when elemtype is `half, `float or `double. Ignored and always treated as false when elemtype is `uint8.

If block is specified, it would be evaluated with a block parameter |array:array|, where array is the created instance. In this case, the block's result would become the function's returned value.

36.5ml.mnist.labelset Class

36.5.1Constructor

mnist.labelset(stream:stream):map {block?}

Reads MNIST label set file from the specified stream and returns a ml.mnist.labelset instance.

If block is specified, it would be evaluated with a block parameter |stream:stream|, where stream is the created instance. In this case, the block's result would become the function's returned value.

36.5.2Property

A ml.mnist.labelset instance has the following properties:

mnist.labelset#nlabelsnumber [read-only]
Number of labels in the database.

36.5.3Method

mnist.labelset#toarray(onehot?:boolean, elemtype?:symbol) {block?}

Creates an array instance from the MNIST label set.

Arguments:

  • onehot .. one-hot data is created when set to true. Raw data is stored otherwise. Default is true.
  • elemtype .. element type of created array that takes `uint8, `half, `float or `double. Default is `float.

If block is specified, it would be evaluated with a block parameter |array:array|, where array is the created instance. In this case, the block's result would become the function's returned value.