Class MnistImageFile
- java.lang.Object
-
- java.io.RandomAccessFile
-
- org.deeplearning4j.datasets.mnist.MnistDbFile
-
- org.deeplearning4j.datasets.mnist.MnistImageFile
-
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable
public class MnistImageFile extends MnistDbFile
-
-
Constructor Summary
Constructors Constructor Description MnistImageFile(String name, String mode)Creates new MNIST database image file ready for reading.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCols()Number of columns per image.intgetEntryLength()Number of bytes for each entry.intgetHeaderSize()protected intgetMagicNumber()MNIST DB files start with unique integer number.intgetRows()Number of rows per image.voidnextImage()Move the cursor to the next image.voidprevImage()Move the cursor to the previous image.int[][]readImage()Reads the image at the current position.byte[][]readImagesUnsafe(int nImages)Read the specified number of images from the current position, to a byte[nImages][rows*cols] Note that MNIST data set is stored as unsigned bytes; this method returns signed bytes without conversion (i.e., same bits, but requires conversion before use)-
Methods inherited from class org.deeplearning4j.datasets.mnist.MnistDbFile
getCount, getCurrentIndex, next, prev, setCurrentIndex
-
Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
-
-
-
Constructor Detail
-
MnistImageFile
public MnistImageFile(String name, String mode) throws IOException
Creates new MNIST database image file ready for reading.- Parameters:
name- the system-dependent filenamemode- the access mode- Throws:
IOExceptionFileNotFoundException
-
-
Method Detail
-
readImage
public int[][] readImage() throws IOExceptionReads the image at the current position.- Returns:
- matrix representing the image
- Throws:
IOException
-
readImagesUnsafe
public byte[][] readImagesUnsafe(int nImages) throws IOExceptionRead the specified number of images from the current position, to a byte[nImages][rows*cols] Note that MNIST data set is stored as unsigned bytes; this method returns signed bytes without conversion (i.e., same bits, but requires conversion before use)- Parameters:
nImages- Number of images- Throws:
IOException
-
nextImage
public void nextImage() throws IOExceptionMove the cursor to the next image.- Throws:
IOException
-
prevImage
public void prevImage() throws IOExceptionMove the cursor to the previous image.- Throws:
IOException
-
getMagicNumber
protected int getMagicNumber()
Description copied from class:MnistDbFileMNIST DB files start with unique integer number.- Specified by:
getMagicNumberin classMnistDbFile- Returns:
- integer number that should be found in the beginning of the file.
-
getRows
public int getRows()
Number of rows per image.- Returns:
- int
-
getCols
public int getCols()
Number of columns per image.- Returns:
- int
-
getEntryLength
public int getEntryLength()
Description copied from class:MnistDbFileNumber of bytes for each entry. Defaults to 1.- Overrides:
getEntryLengthin classMnistDbFile- Returns:
- int
-
getHeaderSize
public int getHeaderSize()
- Overrides:
getHeaderSizein classMnistDbFile
-
-