(path, compute_data_fn)
return result
Computes or loads data.
Computes or loads data.
Computes or loads data .
def compute_or_load_data(path, compute_data_fn):
  """Computes or loads data."""
  if tf.gfile.Exists(path):
    logging.info('Load data from %s', path)
    with tf.gfile.Open(path, 'rb') as f:
      result = np.load(f)
      return result

  result = compute_data_fn()

  logging.info('Save data to %s', path)
  bytes_io = io.BytesIO()
  np.savez(bytes_io, **result)
  with tf.gfile.Open(path, 'wb') as f:
    f.write(bytes_io.getvalue())
  return result
def compute_or_load_data ( path , compute_data_fn ) : if tf . gfile . Exists ( path ) : logging . info ( 'Load data from %s' , path ) with tf . gfile . Open ( path , 'rb' ) as f : result = np . load ( f ) return result result = compute_data_fn ( ) logging . info ( 'Save data to %s' , path ) bytes_io = io . BytesIO ( ) np . savez ( bytes_io , * * result ) with tf . gfile . Open ( path , 'wb' ) as f : f . write ( bytes_io . getvalue ( ) ) return result