bdlb/diabetic_retinopathy_diagnosis/benchmark.py
def load(
      cls,
      level: Union[Text, Level] = "realworld",
      batch_size: int = 64,
      data_dir: Optional[Text] = None,
      as_numpy: bool = False,
  ) -> DataSplits:
    """Loads the datasets for the benchmark.

    Args:
      level: `Level` or `str, downstream task level.
      batch_size: (optional) `int`, number of datapoints
        per mini-batch.
      data_dir: (optional) `str`, path to parent data directory.
      as_numpy: (optional) `bool`, if True returns python generators
        with `numpy.ndarray` outputs.

    Returns:
      A namedtuple with properties:
        * train: `tf.data.Dataset`, train dataset.
        * validation: `tf.data.Dataset`, validation dataset.
        * test: `tf.data.Dataset`, test dataset.
    """
    import tensorflow_datasets as tfds
    from .tfds_adapter import DiabeticRetinopathyDiagnosis

    # Fetch datasets
    try:
      ds_train, ds_validation, ds_test = DiabeticRetinopathyDiagnosis(
          data_dir=data_dir or DATA_DIR,
          config=level).as_dataset(split=["train", "validation", "test"],
                                   shuffle_files=True,
                                   batch_size=batch_size)
    except AssertionError as ae:
      raise AssertionError(
          str(ae) +
          " Run DiabeticRetinopathyDiagnosisBecnhmark.download_and_prepare()"
          " first and then retry.")

    # Parse task level
    level = level if isinstance(level, Level) else Level.from_str(level)
    # Dataset tranformations
    transforms_train, transforms_eval = cls._preprocessors()
    # Apply transformations
    ds_train = ds_train.map(transforms_train,
                            num_parallel_calls=tf.data.experimental.AUTOTUNE)
    ds_validation = ds_validation.map(
        transforms_eval, num_parallel_calls=tf.data.experimental.AUTOTUNE)
    ds_test = ds_test.map(transforms_eval,
                          num_parallel_calls=tf.data.experimental.AUTOTUNE)

    # Prefetches datasets to memory
    ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)
    ds_validation = ds_validation.prefetch(tf.data.experimental.AUTOTUNE)
    ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)

    if as_numpy:
      # Convert to NumPy iterators
      ds_train = tfds.as_numpy(ds_train)
      ds_validation = tfds.as_numpy(ds_validation)
      ds_test = tfds.as_numpy(ds_test)

    return DataSplits(ds_train, ds_validation, ds_test)
Loads the datasets for the benchmark.

    Args:
      level: `Level` or `str, downstream task level.
      batch_size: (optional) `int`, number of datapoints
        per mini-batch.
      data_dir: (optional) `str`, path to parent data directory.
      as_numpy: (optional) `bool`, if True returns python generators
        with `numpy.ndarray` outputs.

    Returns:
      A namedtuple with properties:
        * train: `tf.data.Dataset`, train dataset.
        * validation: `tf.data.Dataset`, validation dataset.
        * test: `tf.data.Dataset`, test dataset.
    
Loads the datasets for the benchmark.
Loads the datasets for the benchmark .
def load(
      cls,
      level: Union[Text, Level] = "realworld",
      batch_size: int = 64,
      data_dir: Optional[Text] = None,
      as_numpy: bool = False,
  ) -> DataSplits:
    import tensorflow_datasets as tfds
    from .tfds_adapter import DiabeticRetinopathyDiagnosis
    try:
      ds_train, ds_validation, ds_test = DiabeticRetinopathyDiagnosis(
          data_dir=data_dir or DATA_DIR,
          config=level).as_dataset(split=["train", "validation", "test"],
                                   shuffle_files=True,
                                   batch_size=batch_size)
    except AssertionError as ae:
      raise AssertionError(
          str(ae) +
          " Run DiabeticRetinopathyDiagnosisBecnhmark.download_and_prepare()"
          " first and then retry.")
    level = level if isinstance(level, Level) else Level.from_str(level)
    transforms_train, transforms_eval = cls._preprocessors()
    ds_train = ds_train.map(transforms_train,
                            num_parallel_calls=tf.data.experimental.AUTOTUNE)
    ds_validation = ds_validation.map(
        transforms_eval, num_parallel_calls=tf.data.experimental.AUTOTUNE)
    ds_test = ds_test.map(transforms_eval,
                          num_parallel_calls=tf.data.experimental.AUTOTUNE)
    ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)
    ds_validation = ds_validation.prefetch(tf.data.experimental.AUTOTUNE)
    ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)
    if as_numpy:
      ds_train = tfds.as_numpy(ds_train)
      ds_validation = tfds.as_numpy(ds_validation)
      ds_test = tfds.as_numpy(ds_test)
    return DataSplits(ds_train, ds_validation, ds_test)
def load ( cls , level : Union [ Text , Level ] = "realworld" , batch_size : int = 64 , data_dir : Optional [ Text ] = None , as_numpy : bool = False , ) -> DataSplits : import tensorflow_datasets as tfds from . tfds_adapter import DiabeticRetinopathyDiagnosis try : ds_train , ds_validation , ds_test = DiabeticRetinopathyDiagnosis ( data_dir = data_dir or DATA_DIR , config = level ) . as_dataset ( split = [ "train" , "validation" , "test" ] , shuffle_files = True , batch_size = batch_size ) except AssertionError as ae : raise AssertionError ( str ( ae ) + " Run DiabeticRetinopathyDiagnosisBecnhmark.download_and_prepare()" " first and then retry." ) level = level if isinstance ( level , Level ) else Level . from_str ( level ) transforms_train , transforms_eval = cls . _preprocessors ( ) ds_train = ds_train . map ( transforms_train , num_parallel_calls = tf . data . experimental . AUTOTUNE ) ds_validation = ds_validation . map ( transforms_eval , num_parallel_calls = tf . data . experimental . AUTOTUNE ) ds_test = ds_test . map ( transforms_eval , num_parallel_calls = tf . data . experimental . AUTOTUNE ) ds_train = ds_train . prefetch ( tf . data . experimental . AUTOTUNE ) ds_validation = ds_validation . prefetch ( tf . data . experimental . AUTOTUNE ) ds_test = ds_test . prefetch ( tf . data . experimental . AUTOTUNE ) if as_numpy : ds_train = tfds . as_numpy ( ds_train ) ds_validation = tfds . as_numpy ( ds_validation ) ds_test = tfds . as_numpy ( ds_test ) return DataSplits ( ds_train , ds_validation , ds_test )
Loads the datasets for the benchmark.
Loads the datasets for the benchmark .
"""Loads the datasets for the benchmark.

    Args:
      level: `Level` or `str, downstream task level.
      batch_size: (optional) `int`, number of datapoints
        per mini-batch.
      data_dir: (optional) `str`, path to parent data directory.
      as_numpy: (optional) `bool`, if True returns python generators
        with `numpy.ndarray` outputs.

    Returns:
      A namedtuple with properties:
        * train: `tf.data.Dataset`, train dataset.
        * validation: `tf.data.Dataset`, validation dataset.
        * test: `tf.data.Dataset`, test dataset.
    """ # Fetch datasets # Parse task level # Dataset tranformations # Apply transformations # Prefetches datasets to memory # Convert to NumPy iterators
A namedtuple with properties:
train: `tf.data.Dataset`, train dataset.
validation: `tf.data.Dataset`, validation dataset.
test: `tf.data.Dataset`, test dataset.
A namedtuple with properties : train : ` tf . data . Dataset ` train dataset . validation : ` tf . data . Dataset ` validation dataset . test : ` tf . data . Dataset ` test dataset .
cls
level
Union[Text, Level]
`Level` or `str, downstream task level.
` Level ` or ` str downstream task level .
batch_size
int
(optional) `int`, number of datapoints
per mini-batch.
( optional ) ` int ` number of datapoints per mini - batch .
data_dir
Optional[Text]
(optional) `str`, path to parent data directory.
( optional ) ` str ` path to parent data directory .
as_numpy
bool
(optional) `bool`, if True returns python generators
with `numpy.ndarray` outputs.
( optional ) ` bool ` if True returns python generators with ` numpy . ndarray ` outputs .