联邦学习数据异构,需要每个用户包含不完全的类别数,但是所有用户数据总和是独立同分布的,包含所有标签的样本,因此在采样的时候需要保证每个用户产生的标签随机数的类别总和等于全样本的标签数。
添加while循环
args.ways = int(args.num_classes * args.degree_noniid)
while True:
local_lb = []
names = locals()
for i in range(args.num_users):
population = args.num_classes
step = 1
sample = [element for element in range(1, population, step)]
names[f'loclb{i}'] = random.sample(range(0,args.num_classes),args.ways)
local_lb.append(names[f'loclb{i}'])
locallb = [token for st in local_lb for token in st]
l = dict(Counter(locallb))
if len(l) == 10 :
break