public class MnistManager
extends java.lang.Object
Utility class for working with the MNIST database.
Provides methods for traversing the images and labels data files separately, as well as simultaneously.
Provides also method for exporting an image by writing it as a PPM file.
Example usage:
MnistManager m = new MnistManager("t10k-images.idx3-ubyte", "t10k-labels.idx1-ubyte"); m.setCurrent(10); //index of the image that we are interested in int[][] image = m.readImage(); System.out.println("Label:" + m.readLabel()); MnistManager.writeImageToPpm(image, "10.ppm");
Constructor and Description |
---|
MnistManager(java.lang.String imagesFile,
java.lang.String labelsFile) |
MnistManager(java.lang.String imagesFile,
java.lang.String labelsFile,
boolean train)
Constructs an instance managing the two given data files.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close any resources opened by the manager.
|
MnistImageFile |
getImages()
Get the underlying images file as
MnistImageFile . |
MnistLabelFile |
getLabels()
Get the underlying labels file as
MnistLabelFile . |
int[][] |
readImage()
Reads the current image.
|
byte[] |
readImageUnsafe(int i) |
int |
readLabel()
Reads the current label.
|
int |
readLabel(int i) |
void |
setCurrent(int index)
Set the position to be read.
|
static void |
writeImageToPpm(int[][] image,
java.lang.String ppmFileName)
Writes the given image in the given file using the PPM data format.
|
public MnistManager(java.lang.String imagesFile, java.lang.String labelsFile, boolean train) throws java.io.IOException
NULL
value for one of the arguments in case reading only one
of the files (images and labels) is required.imagesFile
- Can be NULL
. In that case all future operations
using that file will fail.labelsFile
- Can be NULL
. In that case all future operations
using that file will fail.java.io.IOException
public MnistManager(java.lang.String imagesFile, java.lang.String labelsFile) throws java.io.IOException
java.io.IOException
public static void writeImageToPpm(int[][] image, java.lang.String ppmFileName) throws java.io.IOException
image
- ppmFileName
- java.io.IOException
public int[][] readImage() throws java.io.IOException
java.io.IOException
public byte[] readImageUnsafe(int i)
public void setCurrent(int index)
index
- public int readLabel() throws java.io.IOException
java.io.IOException
public int readLabel(int i)
public MnistImageFile getImages()
MnistImageFile
.MnistImageFile
.public MnistLabelFile getLabels()
MnistLabelFile
.MnistLabelFile
.public void close()