FedProxMNIST#

class fl_sim.data_processing.FedProxMNIST(datadir: Path | str | None = None, transform: str | Callable | None = 'none', seed: int = 0, **extra_config: Any)[source]#

Bases: FedVisionDataset

Federeated MNIST proposed in FedProx.

This dataset is proposed and used in [1] [2], where the data is partitioned in a non-IID manner.

Parameters:
  • 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.

References

property candidate_models: Dict[str, Module]#

A set of candidate models.

property doi: List[str]#

DOIs related to the dataset.

evaluate(probs: Tensor, truths: Tensor) Dict[str, float][source]#

Evaluation using predictions and ground truth.

Parameters:
Returns:

Evaluation results.

Return type:

Dict[str, float]

extra_repr_keys() List[str][source]#

Extra keys for __repr__() and __str__().

get_dataloader(train_bs: int | None = None, test_bs: int | None = None, client_idx: int | None = None) Tuple[DataLoader, DataLoader][source]#

Get local dataloader at client client_idx or get the global dataloader.

Parameters:
  • 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.

Returns:

property label_map: dict#

Label map for the dataset.

random_grid_view(nrow: int, ncol: int, save_path: Path | str | None = None) None[source]#

Select randomly nrow x ncol images from the dataset and plot them in a grid.

Parameters:
  • nrow (int) – Number of rows in the grid.

  • ncol (int) – Number of columns in the grid.

  • save_path (Union[str, Path], optional) – Path to save the figure. If None, do not save the figure.

Return type:

None

property raw_data: Dict[str, ndarray]#

Raw data.

property url: str#

URL for downloading the dataset.

view_image(client_idx: int, image_idx: int) None[source]#

View a single image.

Parameters:
  • client_idx (int) – Index of the client on which the image is located.

  • image_idx (int) – Index of the image in the client.

Return type:

None