slicing#
functions associated with data and dataset slicing
Module Contents#
|
Slice a dataset for non-IID. |
|
Slice a dataset randomly and equally for IID. |
- noniid_slicing(dataset, num_clients, num_shards)#
Slice a dataset for non-IID.
- Parameters
dataset (torch.utils.data.Dataset) – Dataset to slice.
num_clients (int) – Number of client.
num_shards (int) – Number of shards.
Notes
The size of a shard equals to
int(len(dataset)/num_shards)
. Each client will getint(num_shards/num_clients)
shards.- Returns:
dict:
{ 0: indices of dataset, 1: indices of dataset, ..., k: indices of dataset }
- random_slicing(dataset, num_clients)#
Slice a dataset randomly and equally for IID.
- Args:
dataset (torch.utils.data.Dataset): a dataset for slicing. num_clients (int): the number of client.
- Returns:
dict:
{ 0: indices of dataset, 1: indices of dataset, ..., k: indices of dataset }