| 1 | <html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 | <title>IDX file format</title> |
| 3 | <style> |
| 4 | td { padding-left: 5pt; padding-right: 5pt; } |
| 5 | th { padding-left: 5pt; padding-right: 5pt; } |
| 6 | code { white-space: pre-wrap; } |
| 7 | dd { white-space: pre-wrap; } |
| 8 | </style> |
| 9 | </head><body bgcolor="#FFFFFF"> |
| 10 | |
| 11 | <table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 | IDX file format |
| 13 | </b></font></table></table> |
| 14 | <p>The IDX file format is a simple format for vectors and multidimensional matrices of various numerical types. </p> |
| 15 | <p>The basic format according to <i>http://yann.lecun.com/exdb/mnist/</i> is:</p> |
| 16 | <code> magic number<br></code> |
| 17 | <code> size in dimension 1<br></code> |
| 18 | <code> size in dimension 2<br></code> |
| 19 | <code> size in dimension 3<br></code> |
| 20 | <code> ....<br></code> |
| 21 | <code> size in dimension N<br></code> |
| 22 | <code> data<br></code> |
| 23 | <p>The magic number is four bytes long. The first 2 bytes are always 0.</p> |
| 24 | <p>The third byte codes the type of the data:</p> |
| 25 | <code> 0x08: unsigned byte<br></code> |
| 26 | <code> 0x09: signed byte<br></code> |
| 27 | <code> 0x0B: short (2 bytes)<br></code> |
| 28 | <code> 0x0C: int (4 bytes)<br></code> |
| 29 | <code> 0x0D: float (4 bytes)<br></code> |
| 30 | <code> 0x0E: double (8 bytes)<br></code> |
| 31 | <p>The fourth byte codes the number of dimensions of the vector/matrix: 1 for vectors, 2 for matrices....</p> |
| 32 | <p>The sizes in each dimension are 4-byte integers (big-endian, like in most non-Intel processors).</p> |
| 33 | <p>The data is stored like in a C array, i.e. the index in the last dimension changes the fastest.</p> |
| 34 | <h2>Behaviour</h2> |
| 35 | <p>If the storage format indicates that there are more than 2 dimensions, the resulting Matrix accumulates dimensions 2 and higher in the columns. For example, with three dimensions of size n1, n2 and n3, respectively, the resulting Matrix object will have n1 rows and <i>n2×n3</i> columns.</p> |
| 36 | <h2>Example</h2> |
| 37 | <p>The training and testing data of the MNIST database of handwritten digits at http://yann.lecun.com/exdb/mnist/ is stored in <i>compressed</i> IDX formatted files. </p> |
| 38 | <p>Reading the uncompressed file <i>train-images-idx3-ubyte</i> available at http://yann.lecun.com/exdb/mnist/ with 60000 images of 28×28 pixel data, will result in a new Matrix object with 60000 rows and 784 (=28×28) columns. Each cell will contain a number in the interval from 0 to 255.</p> |
| 39 | <p>Reading the uncompressed file <i>train-labels-idx1-ubyte</i> with 60000 labels will result in a new Matrix object with 1 row and 60000 columns. Each cell will contain a number in the interval from 0 to 9.</p> |
| 40 | <hr> |
| 41 | <address> |
| 42 | <p>© djmw 20160220</p> |
| 43 | </address> |
| 44 | </body> |
| 45 | </html> |