Validate that filename corresponds to images for the MNIST dataset.
(filename)
| 39 | |
| 40 | |
| 41 | def check_image_file_header(filename): |
| 42 | """Validate that filename corresponds to images for the MNIST dataset.""" |
| 43 | with tf.gfile.Open(filename, 'rb') as f: |
| 44 | magic = read32(f) |
| 45 | read32(f) # num_images, unused |
| 46 | rows = read32(f) |
| 47 | cols = read32(f) |
| 48 | if magic != 2051: |
| 49 | raise ValueError('Invalid magic number %d in MNIST file %s' % (magic, |
| 50 | f.name)) |
| 51 | if rows != 28 or cols != 28: |
| 52 | raise ValueError( |
| 53 | 'Invalid MNIST file %s: Expected 28x28 images, found %dx%d' % |
| 54 | (f.name, rows, cols)) |
| 55 | |
| 56 | |
| 57 | def check_labels_file_header(filename): |