tff.simulation.TransformingClientData

Class TransformingClientData

Inherits From: ClientData

Defined in simulation/transforming_client_data.py.

Transforms client data, potentially expanding by adding pseudo-clients.

Each client of the raw_client_data is "expanded" into some number of pseudo-clients. Each client ID is a string consisting of the original client ID plus a concatenated integer index. For example, the raw client id "client_a" might be expanded into pseudo-client ids "client_a_0", "client_a_1" and "client_a_2". A function fn(x) maps datapoint x to a new datapoint, where the constructor of fn is parameterized by the (raw) client_id and index i. For example if x is an image, then make_transform_fn("client_a", 0)(x) might be the identity, while make_transform_fn("client_a", 1)(x) could be a random rotation of the image with the angle determined by a hash of "client_a" and "1". Typically by convention the index 0 corresponds to the identity function if the identity is supported.

__init__

__init__(
    raw_client_data,
    make_transform_fn,
    num_transformed_clients
)

Initializes the TransformingClientData.

Args:

  • raw_client_data: A ClientData to expand.
  • make_transform_fn: A function that returns a callable that maps datapoint x to a new datapoint x'. make_transform_fn will be called as make_transform_fn(raw_client_id, i) where i is an integer index, and should return a function fn(x)->x. For example if x is an image, then make_transform_fn("client_a", 0)(x) might be the identity, while make_transform_fn("client_a", 1)(x) could be a random rotation of the image with the angle determined by a hash of "client_a" and "1". If transform_fn_cons returns None, no transformation is performed. Typically by convention the index 0 corresponds to the identity function if the identity is supported.
  • num_transformed_clients: The total number of transformed clients to produce. If it is an integer multiple k of the number of real clients, there will be exactly k pseudo-clients per real client, with indices 0...k-1. Any remainder g will be generated from the first g real clients and will be given index k.

Properties

client_ids

output_shapes

output_types

Methods

create_tf_dataset_for_client

create_tf_dataset_for_client(client_id)

create_tf_dataset_from_all_clients

create_tf_dataset_from_all_clients()

Creates a new tf.data.Dataset containing all client examples.

NOTE: the returned tf.data.Dataset is not serializable and runnable on other devices, as it uses tf.py_func internally.

Returns:

A tf.data.Dataset object.