FedLibSVMDataset#
- class fl_sim.data_processing.FedLibSVMDataset(dataset_name: str, num_clients: int, iid: bool = True, criterion_name: str = 'svm', seed: int = 0)[source]#
Bases:
FedDataset
- evaluate(probs: Tensor, truths: Tensor) Dict[str, float] [source]#
Evaluation using predictions and ground truth.
- Parameters:
probs (torch.Tensor) – Predicted probabilities.
truths (torch.Tensor) – Ground truth labels.
- Returns:
Evaluation results.
- Return type:
- 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:
train_dl (
torch.utils.data.DataLoader
) – Training dataloader.test_dl (
torch.utils.data.DataLoader
) – Testing dataloader.
- load_partition_data(batch_size: int | None = None) tuple [source]#
Partition data into all local clients.
- Parameters:
batch_size (int, optional) – Batch size for dataloader. If
None
, use default batch size.- Returns:
- train_clients_num:
int
Number of training clients.
- train_clients_num:
- train_data_num:
int
Number of training data.
- train_data_num:
- test_data_num:
int
Number of testing data.
- test_data_num:
- train_data_global:
torch.utils.data.DataLoader
Global training dataloader.
- train_data_global:
- test_data_global:
torch.utils.data.DataLoader
Global testing dataloader.
- test_data_global:
- data_local_num_dict:
dict
Number of local training data for each client.
- data_local_num_dict:
- train_data_local_dict:
dict
Local training dataloader for each client.
- train_data_local_dict:
- test_data_local_dict:
dict
Local testing dataloader for each client.
- test_data_local_dict:
- n_class:
int
Number of classes.
- n_class:
- Return type:
- load_partition_data_distributed(process_id: int, batch_size: int | None = None) tuple [source]#
Get local dataloader at client process_id or get global dataloader.
- Parameters:
- Returns:
- train_clients_num:
int
Number of training clients.
- train_clients_num:
- train_data_num:
int
Number of training data.
- train_data_num:
- train_data_global:
torch.utils.data.DataLoader
or None Global training dataloader.
- train_data_global:
- test_data_global:
torch.utils.data.DataLoader
or None Global testing dataloader.
- test_data_global:
- local_data_num:
int
Number of local training data.
- local_data_num:
- train_data_local:
torch.utils.data.DataLoader
or None Local training dataloader.
- train_data_local:
- test_data_local:
torch.utils.data.DataLoader
or None Local testing dataloader.
- test_data_local:
- n_class:
int
Number of classes.
- n_class:
- Return type: