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

Function extract_images

tensorflow/input_data.py:24–39  ·  view source on GitHub ↗

Extract the images into a 4D uint8 numpy array [index, y, x, depth].

(filename)

Source from the content-addressed store, hash-verified

22 dt = numpy.dtype(numpy.uint32).newbyteorder('>')
23 return numpy.frombuffer(bytestream.read(4), dtype=dt)
24def extract_images(filename):
25 """Extract the images into a 4D uint8 numpy array [index, y, x, depth]."""
26 print('Extracting', filename)
27 with gzip.open(filename) as bytestream:
28 magic = _read32(bytestream)
29 if magic != 2051:
30 raise ValueError(
31 'Invalid magic number %d in MNIST image file: %s' %
32 (magic, filename))
33 num_images = _read32(bytestream)
34 rows = _read32(bytestream)
35 cols = _read32(bytestream)
36 buf = bytestream.read(rows * cols * num_images)
37 data = numpy.frombuffer(buf, dtype=numpy.uint8)
38 data = data.reshape(num_images, rows, cols, 1)
39 return data
40def dense_to_one_hot(labels_dense, num_classes=10):
41 """Convert class labels from scalars to one-hot vectors."""
42 num_labels = labels_dense.shape[0]

Callers 1

read_data_setsFunction · 0.85

Calls 1

_read32Function · 0.85

Tested by

no test coverage detected