Extract the labels into a 1D uint8 numpy array [index].
(filename, one_hot=False)
| 45 | labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1 |
| 46 | return labels_one_hot |
| 47 | def extract_labels(filename, one_hot=False): |
| 48 | """Extract the labels into a 1D uint8 numpy array [index].""" |
| 49 | print('Extracting', filename) |
| 50 | with gzip.open(filename) as bytestream: |
| 51 | magic = _read32(bytestream) |
| 52 | if magic != 2049: |
| 53 | raise ValueError( |
| 54 | 'Invalid magic number %d in MNIST label file: %s' % |
| 55 | (magic, filename)) |
| 56 | num_items = _read32(bytestream) |
| 57 | buf = bytestream.read(num_items) |
| 58 | labels = numpy.frombuffer(buf, dtype=numpy.uint8) |
| 59 | if one_hot: |
| 60 | return dense_to_one_hot(labels) |
| 61 | return labels |
| 62 | class DataSet(object): |
| 63 | def __init__(self, images, labels, fake_data=False): |
| 64 | if fake_data: |
no test coverage detected