(dataset_records_path, convert_from_pkl=False)
return data_spec
Loads dataset specification from directory containing the dataset records.

  Newly-generated datasets have the dataset specification serialized as JSON,
  older ones have it as a .pkl file. If no JSON file is present and
  `convert_from_pkl` is passed, this method will load the .pkl and serialize it
  to JSON.

  Args:
    dataset_records_path: A string, the path to the directory containing
      .tfrecords files and dataset_spec.
    convert_from_pkl: A boolean (False by default), whether to convert a
      dataset_spec.pkl file to JSON.

  Returns:
    A DatasetSpecification, BiLevelDatasetSpecification, or
      HierarchicalDatasetSpecification, depending on the dataset.

  Raises:
    RuntimeError: If no suitable dataset_spec file is found in directory
      (.json or .pkl depending on `convert_from_pkl`).
Loads dataset specification from directory containing the dataset records.
Loads dataset specification from directory containing the dataset records .
def load_dataset_spec(dataset_records_path, convert_from_pkl=False):
  """Loads dataset specification from directory containing the dataset records.

  Newly-generated datasets have the dataset specification serialized as JSON,
  older ones have it as a .pkl file. If no JSON file is present and
  `convert_from_pkl` is passed, this method will load the .pkl and serialize it
  to JSON.

  Args:
    dataset_records_path: A string, the path to the directory containing
      .tfrecords files and dataset_spec.
    convert_from_pkl: A boolean (False by default), whether to convert a
      dataset_spec.pkl file to JSON.

  Returns:
    A DatasetSpecification, BiLevelDatasetSpecification, or
      HierarchicalDatasetSpecification, depending on the dataset.

  Raises:
    RuntimeError: If no suitable dataset_spec file is found in directory
      (.json or .pkl depending on `convert_from_pkl`).
  """
  json_path = os.path.join(dataset_records_path, 'dataset_spec.json')
  pkl_path = os.path.join(dataset_records_path, 'dataset_spec.pkl')
  if tf.io.gfile.exists(json_path):
    with tf.io.gfile.GFile(json_path, 'r') as f:
      data_spec = json.load(f, object_hook=as_dataset_spec)
  elif tf.io.gfile.exists(pkl_path):
    if convert_from_pkl:
      logging.info('Loading older dataset_spec.pkl to convert it.')
      with tf.io.gfile.GFile(pkl_path, 'rb') as f:
        data_spec = pkl.load(f)
      with tf.io.gfile.GFile(json_path, 'w') as f:
        json.dump(data_spec.to_dict(), f, indent=2)
    else:
      raise RuntimeError(
          'No dataset_spec.json file found in directory %s, but an older '
          'dataset_spec.pkl was found. You can try to pass '
          '`convert_from_pkl=True` to convert it, or you may need to run the '
          'conversion again in order to make sure you have the latest version.'
          % dataset_records_path)
  else:
    raise RuntimeError('No dataset_spec file found in directory %s' %
                       dataset_records_path)

  # Replace outdated path of where to find the dataset's records.
  data_spec = data_spec._replace(path=dataset_records_path)
  data_spec.initialize()
  return data_spec
def load_dataset_spec ( dataset_records_path , convert_from_pkl = False ) : json_path = os . path . join ( dataset_records_path , 'dataset_spec.json' ) pkl_path = os . path . join ( dataset_records_path , 'dataset_spec.pkl' ) if tf . io . gfile . exists ( json_path ) : with tf . io . gfile . GFile ( json_path , 'r' ) as f : data_spec = json . load ( f , object_hook = as_dataset_spec ) elif tf . io . gfile . exists ( pkl_path ) : if convert_from_pkl : logging . info ( 'Loading older dataset_spec.pkl to convert it.' ) with tf . io . gfile . GFile ( pkl_path , 'rb' ) as f : data_spec = pkl . load ( f ) with tf . io . gfile . GFile ( json_path , 'w' ) as f : json . dump ( data_spec . to_dict ( ) , f , indent = 2 ) else : raise RuntimeError ( 'No dataset_spec.json file found in directory %s, but an older ' 'dataset_spec.pkl was found. You can try to pass ' '`convert_from_pkl=True` to convert it, or you may need to run the ' 'conversion again in order to make sure you have the latest version.' % dataset_records_path ) else : raise RuntimeError ( 'No dataset_spec file found in directory %s' % dataset_records_path ) # Replace outdated path of where to find the dataset's records. data_spec = data_spec . _replace ( path = dataset_records_path ) data_spec . initialize ( ) return data_spec