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 int
getCols()
Number of columns per image.int
getEntryLength()
Number of bytes for each entry.int
getHeaderSize()
protected int
getMagicNumber()
MNIST DB files start with unique integer number.int
getRows()
Number of rows per image.void
nextImage()
Move the cursor to the next image.void
prevImage()
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:
IOException
FileNotFoundException
-
-
Method Detail
-
readImage
public int[][] readImage() throws IOException
Reads the image at the current position.- Returns:
- matrix representing the image
- Throws:
IOException
-
readImagesUnsafe
public byte[][] readImagesUnsafe(int nImages) throws IOException
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)- Parameters:
nImages
- Number of images- Throws:
IOException
-
nextImage
public void nextImage() throws IOException
Move the cursor to the next image.- Throws:
IOException
-
prevImage
public void prevImage() throws IOException
Move the cursor to the previous image.- Throws:
IOException
-
getMagicNumber
protected int getMagicNumber()
Description copied from class:MnistDbFile
MNIST DB files start with unique integer number.- Specified by:
getMagicNumber
in 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:MnistDbFile
Number of bytes for each entry. Defaults to 1.- Overrides:
getEntryLength
in classMnistDbFile
- Returns:
- int
-
getHeaderSize
public int getHeaderSize()
- Overrides:
getHeaderSize
in classMnistDbFile
-
-