(f)
Extract the images into a 4D uint8 np array [index, y, x, depth].

  Args:
    f: A file object that can be passed into a gzip reader.

  Returns:
    data: A 4D uint8 np array [index, y, x, depth].

  Raises:
    ValueError: If the bytestream does not start with 2051.
Extract the images into a 4D uint8 np array [index, y, x, depth].
Extract the images into a 4D uint8 np array [ index y x depth ] .
def extract_images(f):
  """Extract the images into a 4D uint8 np array [index, y, x, depth].

  Args:
    f: A file object that can be passed into a gzip reader.

  Returns:
    data: A 4D uint8 np array [index, y, x, depth].

  Raises:
    ValueError: If the bytestream does not start with 2051.
  """
  tf.logging.info('Extracting', f.name)
  with gzip.GzipFile(fileobj=f) as bytestream:
    magic = _read32(bytestream)
    if magic != 2051:
      raise ValueError(
          'Invalid magic number %d in MNIST image file: %s' % (magic, f.name))
    num_images = _read32(bytestream)
    rows = _read32(bytestream)
    cols = _read32(bytestream)
    buf = bytestream.read(rows * cols * num_images)
    data = np.frombuffer(buf, dtype=np.uint8)
    data = data.reshape(num_images, rows, cols, 1)
    return data
def extract_images ( f ) : tf . logging . info ( 'Extracting' , f . name ) with gzip . GzipFile ( fileobj = f ) as bytestream : magic = _read32 ( bytestream ) if magic != 2051 : raise ValueError ( 'Invalid magic number %d in MNIST image file: %s' % ( magic , f . name ) ) num_images = _read32 ( bytestream ) rows = _read32 ( bytestream ) cols = _read32 ( bytestream ) buf = bytestream . read ( rows * cols * num_images ) data = np . frombuffer ( buf , dtype = np . uint8 ) data = data . reshape ( num_images , rows , cols , 1 ) return data