MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / extract_labels

Function extract_labels

tensorpack/dataflow/dataset/mnist.py:49–60  ·  view source on GitHub ↗

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

(filename)

Source from the content-addressed store, hash-verified

47
48
49def 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
63class Mnist(RNGDataFlow):

Callers 1

get_images_and_labelsMethod · 0.85

Calls 3

_read32Function · 0.85
openMethod · 0.80
readMethod · 0.80

Tested by

no test coverage detected