MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / extract_labels

Function extract_labels

tensorflow/input_data.py:47–61  ·  view source on GitHub ↗

Extract the labels into a 1D uint8 numpy array [index].

(filename, one_hot=False)

Source from the content-addressed store, hash-verified

45 labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1
46 return labels_one_hot
47def 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
62class DataSet(object):
63 def __init__(self, images, labels, fake_data=False):
64 if fake_data:

Callers 1

read_data_setsFunction · 0.85

Calls 2

_read32Function · 0.85
dense_to_one_hotFunction · 0.85

Tested by

no test coverage detected