def extract_mnist_data(filename, num_images, image_size, pixel_depth):
 if (not tf.gfile.Exists((filename + '.npy'))):
  with gzip.open(filename) as bytestream:
   bytestream.read(16)
   buf = bytestream.read(((image_size * image_size) * num_images))
   data = np.frombuffer(buf, dtype=np.uint8).astype(np.float32)
   data = ((data - (pixel_depth / 2.0)) / pixel_depth)
   data = data.reshape(num_images, image_size, image_size, 1)
   np.save(filename, data)
   return data
 else:
  with tf.gfile.Open((filename + '.npy'), mode='r') as file_obj:
   return np.load(file_obj)

def extract_mnist_data ( filename , num_images , image_size , pixel_depth ) : if ( not tf . gfile . Exists ( ( filename + '.npy' ) ) ) : with gzip . open ( filename ) as bytestream : bytestream . read ( 16 ) buf = bytestream . read ( ( ( image_size * image_size ) * num_images ) ) data = np . frombuffer ( buf , dtype = np . uint8 ) . astype ( np . float32 ) data = ( ( data - ( pixel_depth / 2.0 ) ) / pixel_depth ) data = data . reshape ( num_images , image_size , image_size , 1 ) np . save ( filename , data ) return data else : with tf . gfile . Open ( ( filename + '.npy' ) , mode = 'r' ) as file_obj : return np . load ( file_obj )
extract the images into a 4d tensor [image index .