FedTinyImageNet#

class fl_sim.data_processing.FedTinyImageNet(datadir: str | Path | None = None, num_clients: int = 100, alpha: float = 0.5, transform: str | Callable | None = 'none', seed: int = 0)#

基类:FedVisionDataset

Tiny ImageNet dataset.

The Tiny ImageNet dataset is a subset of the ImageNet dataset. It consists of 200 classes, each with 500 training images and 50 validation images and 50 test images. The images are downsampled to 64x64 pixels.

The original dataset [1] contains the test images while the hugingface dataset [2] does not contain the test images. We use the hugingface dataset [2] for simplicity, and treat the validation set as the test set. See also the Kaggle competition [3] for more details.

参数:
  • datadir (Union[pathlib.Path, str], optional) -- Directory to store data. If None, use default directory.

  • num_clients (int, default 100) -- Number of clients.

  • alpha (float, default 0.5) -- Concentration parameter for the Dirichlet distribution.

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

引用

property candidate_models: Dict[str, Module]#

A set of candidate models.

property doi: List[str]#

DOI(s) related to the dataset.

evaluate(probs: Tensor, truths: Tensor) → Dict[str, float][源代码]#

Evaluation using predictions and ground truth.

参数:
返回:

Evaluation results.

返回类型:

Dict[str, float]

extra_repr_keys() → List[str][源代码]#

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][源代码]#

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.

返回:

property label_map: dict#

Label map for the dataset.

random_grid_view(nrow: int, ncol: int, save_path: str | Path | None = None) → None[源代码]#

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

参数:
  • 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.

返回类型:

None

property url: str#

URL for downloading the original dataset.

view_image(client_idx: int, image_idx: int) → None[源代码]#

View a single image.

参数:
  • client_idx (int) -- Index of the client on which the image is located.

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

返回类型:

None