FedEMNIST#
- class fl_sim.data_processing.FedEMNIST(datadir: str | Path | None = None, transform: str | Callable | None = 'none', seed: int = 0, **extra_config: Any)#
-
Federated EMNIST dataset.
This dataset extends MNIST dataset with upper and lower case English characters. Data partition is the same as TensorFlow Federated (TFF) [1] with the following statistics:
DATASET
TRAIN CLIENTS
TRAIN EXAMPLES
TEST CLIENTS
TEST EXAMPLES
EMNIST-62
3,400
671,585
3,400
77,483
Most methods in this class are modified from FedML [2].
- 参数:
datadir (Union[pathlib.Path, str], optional) -- Directory to store data. If
None, use default directory.transform (Union[str, Callable], default "none") -- Transform to apply to data. Conventions:
"none"means no transform, using TensorDataset.seed (int, default 0) -- Random seed for data partitioning.
**extra_config (dict, optional) -- Extra configurations.
备注
The images are processed using min-max normalization to range 0 to 1.
引用
- evaluate(probs: Tensor, truths: Tensor) Dict[str, float][源代码]#
Evaluation using predictions and ground truth.
- 参数:
probs (torch.Tensor) -- Predicted probabilities.
truths (torch.Tensor) -- Ground truth labels.
- 返回:
Evaluation results.
- 返回类型:
- get_dataloader(train_bs: int | None = None, test_bs: int | None = None, client_idx: int | None = None) Tuple[DataLoader, DataLoader][源代码]#
Get local dataloader at client client_idx or get the global dataloader.
- 参数:
train_bs (int, optional) -- Batch size for training dataloader. If
None, use default batch size.test_bs (int, optional) -- Batch size for testing dataloader. If
None, use default batch size.client_idx (int, optional) -- Index of the client to get dataloader. If
None, get the dataloader containing all data. Usually used for centralized training.
- 返回:
train_dl (
torch.utils.data.DataLoader) -- Training dataloader.test_dl (
torch.utils.data.DataLoader) -- Testing dataloader.