Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'DatasetSplit' object has no attribute 'classes' #2

Open
DENGhy123 opened this issue Mar 25, 2023 · 1 comment
Open

Comments

@DENGhy123
Copy link

When I run main_fedIPR.py", it report an error "AttributeError: 'DatasetSplit' object has no attribute 'classes'". Is that missing a function "classes" in the Class 'DatasetSplit'? Hope to hear you. Thank you. @purp1eHaze

@ikazuchi233
Copy link

ikazuchi233 commented Jun 19, 2023

在试图跑非iid场景时,我也遇到了这个问题。以下是我解决这个问题的思路:
代码的编写者使用自定义的DatasetSplit类(在datasets.py中)将Dataset进行了包装。具体来说,DatasetSplit中储存的每一条数据都有一个id。id是为了方便将数据分配给不同的客户端,以模拟联邦学习的场景。
在出现问题的代码(在我这里,导致该问题的代码是sampling.py中的cifar_beta方法)处,编写者使用名为dataset的变量接住传入的DatasetSplit类对象。然而,DatasetSplit是对Dataset类的包装。编写者似乎忘了dataset它是DatasetSplit对象,而误认为它是Dataset对象。想要正确的使用该方法,你需要将出现的dataset.classes改为dataset.dataset.classes。将dataset.targets改为dataset.dataset.targets。此外,在最后的for循环“for i in range(n_clients):”中,你要将client_datasets.append(subset)改为client_datasets.append(client_i_idx)。这是因为在iid场景对应的方法cifar_iid中,返回的对象是包含id的二级列表。在别的方法中会使用这个列表对数据集进行切分。然而,在cifar_beta中,编写者已经使用client_i_idx对数据集进行切分,并返回切分后的Subset对象组成的列表。这是不对的,因为cifar_iid和cifar_beta共用之后的代码,这会导致cifar_beta切分后的数据集被再次切分。
希望这能解决你的问题。 @DENGhy123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants