federated/data/data_preprocessing.py
def preprocess_dataset(
    epochs: int, batch_size: int, shuffle_buffer_size: int
) -> Callable[[tf.data.Dataset], tf.data.Dataset]:
    """Function returns a function for preprocessing of a dataset.

    Args:
        epochs (int): How many times to repeat a batch.\n
        batch_size (int): Batch size.\n
        shuffle_buffer_size (int): Buffer size for shuffling the dataset.\n

    Returns:
        Callable[[tf.data.Dataset], tf.data.Dataset]: A callable for preprocessing a dataset object.
    """

    def _reshape(element: collections.OrderedDict) -> tf.Tensor:

        return (tf.expand_dims(element["datapoints"], axis=-1), element["label"])

    @tff.tf_computation(
        tff.SequenceType(
            collections.OrderedDict(
                label=tff.TensorType(tf.int32, shape=(5,)),
                datapoints=tff.TensorType(tf.float32, shape=(186,)),
            )
        )
    )
    def preprocess(dataset: tf.data.Dataset) -> tf.data.Dataset:
        """
        Function returns shuffled dataset
        """
        return (
            dataset.shuffle(shuffle_buffer_size)
            .repeat(epochs)
            .batch(batch_size, drop_remainder=False)
            .map(_reshape, num_parallel_calls=tf.data.experimental.AUTOTUNE)
        )

    return preprocess
Function returns a function for preprocessing of a dataset.

    Args:
        epochs (int): How many times to repeat a batch.\n
        batch_size (int): Batch size.\n
        shuffle_buffer_size (int): Buffer size for shuffling the dataset.\n

    Returns:
        Callable[[tf.data.Dataset], tf.data.Dataset]: A callable for preprocessing a dataset object.
    
Function returns a function for preprocessing of a dataset.
Function returns a function for preprocessing of a dataset .
def preprocess_dataset(
    epochs: int, batch_size: int, shuffle_buffer_size: int
) -> Callable[[tf.data.Dataset], tf.data.Dataset]:
    def _reshape(element: collections.OrderedDict) -> tf.Tensor:
        return (tf.expand_dims(element["datapoints"], axis=-1), element["label"])
    @tff.tf_computation(
        tff.SequenceType(
            collections.OrderedDict(
                label=tff.TensorType(tf.int32, shape=(5,)),
                datapoints=tff.TensorType(tf.float32, shape=(186,)),
            )
        )
    )
    def preprocess(dataset: tf.data.Dataset) -> tf.data.Dataset:
        return (
            dataset.shuffle(shuffle_buffer_size)
            .repeat(epochs)
            .batch(batch_size, drop_remainder=False)
            .map(_reshape, num_parallel_calls=tf.data.experimental.AUTOTUNE)
        )
    return preprocess
def preprocess_dataset ( epochs : int , batch_size : int , shuffle_buffer_size : int ) -> Callable [ [ tf . data . Dataset ] , tf . data . Dataset ] : def _reshape ( element : collections . OrderedDict ) -> tf . Tensor : return ( tf . expand_dims ( element [ "datapoints" ] , axis = - 1 ) , element [ "label" ] ) @ tff . tf_computation ( tff . SequenceType ( collections . OrderedDict ( label = tff . TensorType ( tf . int32 , shape = ( 5 , ) ) , datapoints = tff . TensorType ( tf . float32 , shape = ( 186 , ) ) , ) ) ) def preprocess ( dataset : tf . data . Dataset ) -> tf . data . Dataset : """
        Function returns shuffled dataset
        """ return ( dataset . shuffle ( shuffle_buffer_size ) . repeat ( epochs ) . batch ( batch_size , drop_remainder = False ) . map ( _reshape , num_parallel_calls = tf . data . experimental . AUTOTUNE ) ) return preprocess
Function returns a function for preprocessing of a dataset.
Function returns a function for preprocessing of a dataset .
"""Function returns a function for preprocessing of a dataset.

    Args:
        epochs (int): How many times to repeat a batch.\n
        batch_size (int): Batch size.\n
        shuffle_buffer_size (int): Buffer size for shuffling the dataset.\n

    Returns:
        Callable[[tf.data.Dataset], tf.data.Dataset]: A callable for preprocessing a dataset object.
    """ """
        Function returns shuffled dataset
        """
A callable for preprocessing a dataset object.
A callable for preprocessing a dataset object .
Callable[[tf.data.Dataset], tf.data.Dataset]
epochs
int
None
batch_size
int
None
shuffle_buffer_size
int
Buffer size for shuffling the dataset.\n
Buffer size for shuffling the dataset . \ n