bdlb/diabetic_retinopathy_diagnosis/benchmark.py
def _preprocessors(cls) -> Tuple[transforms.Transform, transforms.Transform]:
    """Applies transformations to the raw data."""
    import tensorflow_datasets as tfds

    # Transformation hyperparameters
    mean = np.asarray([0.42606387, 0.29752496, 0.21309826])
    stddev = np.asarray([0.27662534, 0.20280295, 0.1687619])

    class Parse(transforms.Transform):
      """Parses datapoints from raw `tf.data.Dataset`."""

      def __call__(self, x, y=None):
        """Returns `as_supervised` tuple."""
        return x["image"], x["label"]

    class CastX(transforms.Transform):
      """Casts image to `dtype`."""

      def __init__(self, dtype):
        """Constructs a type caster."""
        self.dtype = dtype

      def __call__(self, x, y):
        """Returns casted image (to `dtype`) and its (unchanged) label as
        tuple."""
        return tf.cast(x, self.dtype), y

    class To01X(transforms.Transform):
      """Rescales image to [min, max]=[0, 1]."""

      def __call__(self, x, y):
        """Returns rescaled image and its (unchanged) label as tuple."""
        return x / 255.0, y

    # Get augmentation schemes
    [augmentation_config,
     no_augmentation_config] = cls._ImageDataGenerator_config()

    # Transformations for train dataset
    transforms_train = transforms.Compose([
        Parse(),
        CastX(tf.float32),
        To01X(),
        transforms.Normalize(mean, stddev),
        # TODO(filangel): hangle batch with ImageDataGenerator
        # transforms.RandomAugment(**augmentation_config),
    ])

    # Transformations for validation/test dataset
    transforms_eval = transforms.Compose([
        Parse(),
        CastX(tf.float32),
        To01X(),
        transforms.Normalize(mean, stddev),
        # TODO(filangel): hangle batch with ImageDataGenerator
        # transforms.RandomAugment(**no_augmentation_config),
    ])

    return transforms_train, transforms_eval
Applies transformations to the raw data.
Applies transformations to the raw data.
Applies transformations to the raw data .
def _preprocessors(cls) -> Tuple[transforms.Transform, transforms.Transform]:
    import tensorflow_datasets as tfds
    mean = np.asarray([0.42606387, 0.29752496, 0.21309826])
    stddev = np.asarray([0.27662534, 0.20280295, 0.1687619])
    class Parse(transforms.Transform):
      def __call__(self, x, y=None):
        return x["image"], x["label"]
    class CastX(transforms.Transform):
      def __init__(self, dtype):
        self.dtype = dtype
      def __call__(self, x, y):
        return tf.cast(x, self.dtype), y
    class To01X(transforms.Transform):
      def __call__(self, x, y):
        return x / 255.0, y
    [augmentation_config,
     no_augmentation_config] = cls._ImageDataGenerator_config()
    transforms_train = transforms.Compose([
        Parse(),
        CastX(tf.float32),
        To01X(),
        transforms.Normalize(mean, stddev),
    ])
    transforms_eval = transforms.Compose([
        Parse(),
        CastX(tf.float32),
        To01X(),
        transforms.Normalize(mean, stddev),
    ])
    return transforms_train, transforms_eval
def _preprocessors ( cls ) -> Tuple [ transforms . Transform , transforms . Transform ] : import tensorflow_datasets as tfds mean = np . asarray ( [ 0.42606387 , 0.29752496 , 0.21309826 ] ) stddev = np . asarray ( [ 0.27662534 , 0.20280295 , 0.1687619 ] ) class Parse ( transforms . Transform ) : """Parses datapoints from raw `tf.data.Dataset`.""" def __call__ ( self , x , y = None ) : """Returns `as_supervised` tuple.""" return x [ "image" ] , x [ "label" ] class CastX ( transforms . Transform ) : """Casts image to `dtype`.""" def __init__ ( self , dtype ) : """Constructs a type caster.""" self . dtype = dtype def __call__ ( self , x , y ) : """Returns casted image (to `dtype`) and its (unchanged) label as
        tuple.""" return tf . cast ( x , self . dtype ) , y class To01X ( transforms . Transform ) : """Rescales image to [min, max]=[0, 1].""" def __call__ ( self , x , y ) : """Returns rescaled image and its (unchanged) label as tuple.""" return x / 255.0 , y [ augmentation_config , no_augmentation_config ] = cls . _ImageDataGenerator_config ( ) transforms_train = transforms . Compose ( [ Parse ( ) , CastX ( tf . float32 ) , To01X ( ) , transforms . Normalize ( mean , stddev ) , ] ) transforms_eval = transforms . Compose ( [ Parse ( ) , CastX ( tf . float32 ) , To01X ( ) , transforms . Normalize ( mean , stddev ) , ] ) return transforms_train , transforms_eval
Applies transformations to the raw data.
Applies transformations to the raw data .
"""Applies transformations to the raw data.""" # Transformation hyperparameters """Parses datapoints from raw `tf.data.Dataset`.""" """Returns `as_supervised` tuple.""" """Casts image to `dtype`.""" """Constructs a type caster.""" """Returns casted image (to `dtype`) and its (unchanged) label as
        tuple.""" """Rescales image to [min, max]=[0, 1].""" """Returns rescaled image and its (unchanged) label as tuple.""" # Get augmentation schemes # Transformations for train dataset # TODO(filangel): hangle batch with ImageDataGenerator # transforms.RandomAugment(**augmentation_config), # Transformations for validation/test dataset # TODO(filangel): hangle batch with ImageDataGenerator # transforms.RandomAugment(**no_augmentation_config),
cls