Seite 1 von 1

Verstehe das IDX-Format nicht

Verfasst: Sonntag 26. April 2020, 08:46
von naheliegend
Hi,

ich möchte mein neuronales Netz mit Hilfe von Bildern trainieren. Im Internet habe ich folgendes gefunden:

http://yann.lecun.com/exdb/mnist/

Es ist eine .gz Datei mit irgendwelchen Bildern im IDX-Format?
THE IDX FILE FORMAT

the IDX file format is a simple format for vectors and multidimensional matrices of various numerical types.
The basic format is

magic number
size in dimension 0
size in dimension 1
size in dimension 2
.....
size in dimension N
data

The magic number is an integer (MSB first). The first 2 bytes are always 0.

The third byte codes the type of the data:
0x08: unsigned byte
0x09: signed byte
0x0B: short (2 bytes)
0x0C: int (4 bytes)
0x0D: float (4 bytes)
0x0E: double (8 bytes)

The 4-th byte codes the number of dimensions of the vector/matrix: 1 for vectors, 2 for matrices....

The sizes in each dimension are 4-byte integers (MSB first, high endian, like in most non-Intel processors).

The data is stored like in a C array, i.e. the index in the last dimension changes the fastest.
TRAINING SET IMAGE FILE (train-images-idx3-ubyte):

[offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 60000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).


und dazu fand ich den Code, bzgl des Einlesens:

Code: Alles auswählen

 
 with gzip.open(filename, 'rb') as f:  
            data = np.frombuffer(f.read(), np.uint8, offset=16)
            data = data.reshape(-1, 1, 28, 28)
            return data/np.float(256) 


Meine Fragen:

Was ist das IDX-Format? Ich verstehe das nicht so recht.
Wie funktioniert der Einlesecode? Woher weiß ich, dass es np.uint8 und einen offset von 16 hat?
Warum wird np.frombuffer() genutzt?

Gruß und vielen Dank

Re: Verstehe das IDX-Format nicht

Verfasst: Sonntag 26. April 2020, 09:30
von Sirius3
Da weiß jemand schon ganz genau, welches Format die Daten haben und überspringt den Header einfach. Pech,wenn das nicht der Fall ist.
Das was in der Beschreibung magic number heißt, ist oben genau aufgeschlüsselt: 08 bedeutet uint8 und 03 drei Dimensionen. Danach kommt die Größe: 6000×28×28.

Re: Verstehe das IDX-Format nicht

Verfasst: Sonntag 26. April 2020, 15:59
von naheliegend
Sirius3 hat geschrieben: Sonntag 26. April 2020, 09:30 Da weiß jemand schon ganz genau, welches Format die Daten haben und überspringt den Header einfach. Pech,wenn das nicht der Fall ist.
Das was in der Beschreibung magic number heißt, ist oben genau aufgeschlüsselt: 08 bedeutet uint8 und 03 drei Dimensionen. Danach kommt die Größe: 6000×28×28.
Ah, das hilft auf jeden Fall schonmal. Ist das immer so? Ich weiß nicht ob ich das Wissen auf einen neuen Anwendungsfall transferieren könnte. :-/

Re: Verstehe das IDX-Format nicht

Verfasst: Sonntag 26. April 2020, 16:31
von __deets__
Ja, das ist immer so.