Class Mnist

java.lang.Object
ai.beestream.jitnn.data.Mnist
All Implemented Interfaces:
Dataset

public final class Mnist extends Object implements Dataset
Reads the MNIST IDX files (train-images-idx3-ubyte[.gz] and friends) from a directory. Pixels are scaled to [0, 1] and normalised with the usual mean 0.1307 and std 0.3081.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The number of images.
    final float[]
    The images [count, 28 * 28], row-major.
    final int[]
    The digit of each image.
    static final int
    Pixels per image.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    batch(int b, int size, float[] x, int[] y)
    Copies batch b (of size size) of images into x and labels into y.
    int
    The number of samples.
    static boolean
    Whether dir holds the MNIST training images (plain or gzipped).
    static Mnist
    load(Path dir, boolean train)
    Pixels normalised with MNIST's mean and standard deviation (0.1307, 0.3081).
    static Mnist
    load(Path dir, boolean train, boolean unit)
    With unit, pixels are raw / 255 in [0, 1] (targets for generative models); otherwise normalised.
    void
    sample(int i, float[] x, int xAt, int[] y, int yAt)
    Copies sample i into x at xAt and its label into y at yAt (DataLoader assembles shuffled batches with it).
    int[]
    The shape of one sample, e.g. {1, 28, 28} or {3, 32, 32}.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface Dataset

    sampleSize
  • Field Details

    • images

      public final float[] images
      The images [count, 28 * 28], row-major.
    • labels

      public final int[] labels
      The digit of each image.
    • count

      public final int count
      The number of images.
    • PIXELS

      public static final int PIXELS
      Pixels per image.
      See Also:
  • Method Details

    • load

      public static Mnist load(Path dir, boolean train) throws IOException
      Pixels normalised with MNIST's mean and standard deviation (0.1307, 0.3081).
      Throws:
      IOException
    • load

      public static Mnist load(Path dir, boolean train, boolean unit) throws IOException
      With unit, pixels are raw / 255 in [0, 1] (targets for generative models); otherwise normalised.
      Throws:
      IOException
    • isPresent

      public static boolean isPresent(Path dir)
      Whether dir holds the MNIST training images (plain or gzipped).
    • count

      public int count()
      Description copied from interface: Dataset
      The number of samples.
      Specified by:
      count in interface Dataset
    • sampleShape

      public int[] sampleShape()
      Description copied from interface: Dataset
      The shape of one sample, e.g. {1, 28, 28} or {3, 32, 32}.
      Specified by:
      sampleShape in interface Dataset
    • batch

      public void batch(int b, int size, float[] x, int[] y)
      Copies batch b (of size size) of images into x and labels into y.
      Specified by:
      batch in interface Dataset
    • sample

      public void sample(int i, float[] x, int xAt, int[] y, int yAt)
      Description copied from interface: Dataset
      Copies sample i into x at xAt and its label into y at yAt (DataLoader assembles shuffled batches with it). The default copies through Dataset.batch(int, int, float[], int[]) of size 1.
      Specified by:
      sample in interface Dataset