Extract the labels into a 1D uint8 numpy array [index].
(filename)
| 47 | |
| 48 | |
| 49 | def extract_labels(filename): |
| 50 | """Extract the labels into a 1D uint8 numpy array [index].""" |
| 51 | with gzip.open(filename) as bytestream: |
| 52 | magic = _read32(bytestream) |
| 53 | if magic != 2049: |
| 54 | raise ValueError( |
| 55 | 'Invalid magic number %d in MNIST label file: %s' % |
| 56 | (magic, filename)) |
| 57 | num_items = _read32(bytestream) |
| 58 | buf = bytestream.read(num_items) |
| 59 | labels = numpy.frombuffer(buf, dtype=numpy.uint8) |
| 60 | return labels |
| 61 | |
| 62 | |
| 63 | class Mnist(RNGDataFlow): |
no test coverage detected