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)
Constructs an instance managing the two given data files.
|
| Modifier and Type | Method and Description |
|---|---|
MnistImageFile |
getImages()
Get the underlying images file as
MnistImageFile. |
MnistLabelFile |
getLabels()
Get the underlying labels file as
MnistLabelFile. |
int[][] |
readImage()
Reads the current image.
|
int |
readLabel()
Reads the current label.
|
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)
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.IOExceptionpublic static void writeImageToPpm(int[][] image,
java.lang.String ppmFileName)
throws java.io.IOException
image - ppmFileName - java.io.IOExceptionpublic int[][] readImage()
throws java.io.IOException
java.io.IOExceptionpublic void setCurrent(int index)
index - public int readLabel()
throws java.io.IOException
java.io.IOExceptionpublic MnistImageFile getImages()
MnistImageFile.MnistImageFile.public MnistLabelFile getLabels()
MnistLabelFile.MnistLabelFile.