Skip to content

Commit

Permalink
Merge branch 'data-partition' of github.com:SMILELab-FL/FedLab into m…
Browse files Browse the repository at this point in the history
…erge
  • Loading branch information
dunzeng committed Sep 24, 2021
2 parents 9d1035a + 6757263 commit 047f007
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions fedlab/utils/dataset/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import numpy as np
import pandas as pd
import warnings


Expand Down Expand Up @@ -240,3 +241,11 @@ def client_inner_dirichlet_partition(targets, num_clients, num_classes, dir_alph

client_dict = dict([(cid, client_indices[cid]) for cid in range(num_clients)])
return client_dict


def samples_num_count(client_dict, num_clients):
client_samples_nums = [[cid, client_dict[cid].shape[0]] for cid in
range(num_clients)]
client_sample_count = pd.DataFrame(data=client_samples_nums,
columns=['client', 'num_samples']).set_index('client')
return client_sample_count
6 changes: 2 additions & 4 deletions fedlab/utils/dataset/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def __getitem__(self, index):
def __len__(self):
raise NotImplementedError

@abstractmethod
def _samples_num_count(self):
raise NotImplementedError


class CIFAR10Partitioner(DataPartitioner):
"""CIFAR10 data partitioner.
Expand Down Expand Up @@ -127,6 +123,8 @@ def __init__(self, targets, num_clients,

# perform partition according to setting
self.client_dict = self._perform_partition()
# get sample number count for each client
self.client_sample_count = F.samples_num_count(self.client_dict, self.num_clients)

def _perform_partition(self):
if self.balance is None:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy
pandas
spacy
pynvml

Expand Down

0 comments on commit 047f007

Please sign in to comment.