Hello,
I am trying to split Cifar10 to get two subsets (Animals and Vehicles). I was able to successfully separate them by the labels
partitioner = IidPartitioner(num_partitions=1)
fds = FederatedDataset(dataset="uoft-cs/cifar10", partitioners={"train": partitioner},)
partition1_train_test = fds.load_partition(0).train_test_split(test_size=0.2, seed=42)
pytorch_transforms = Compose([ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
def apply_transforms(batch):
"""Apply transforms to the partition from FederatedDataset."""
batch["img"] = [pytorch_transforms(img) for img in batch["img"]]
return batch
partition_train_test = partition_train_test.with_transform(apply_transforms)
labels_list_partition1_train = [item['label'] for item in partition_train_test['train']]
animals = torch.tensor([2, 3, 4, 5, 6, 7])
animalsindicesTrain = (torch.tensor(labels_list_partition1_train)[..., None] == animals).any(-1).nonzero(as_tuple=True)[0]
animalsTrainSubset = torch.utils.data.Subset(partition1_train_test['train'], animalsindicesTrain)
animalsTrainDataloader = DataLoader(animalsTrainSubset, batch_size=128, shuffle=True, num_workers=2)
But I still have 10 classes in that subset and I would like it to have 6 for animals and 4 for vehicles. Is in my interest to have different length heads as I am doing some tests with federated environments.
Is there any straight forward way of reducing the number of classes of the subsets?
Thank you in advance.