【发布时间】:2021-06-02 22:20:09
【问题描述】:
我正在使用联邦学习。我正在使用一个全局服务器,我在其中定义了一个基于 cnn 的分类器。全局服务器使用超参数编译模型并将其发送到边缘(客户端),目前我正在使用两个客户端。每个客户端都使用其本地数据(现在我使用相同的数据,并在每个客户端上建模)。训练模型后,每个客户在其本地模型中的准确率、准确率和召回率都在 95% 以上。客户端将他们训练有素的本地模型发送到服务器。服务器获取模型并从每个接收到的模型中获取权重,并根据this formula 计算平均值。下面是我为在 python 中实现这个公式而编写的代码。当我为模型设置平均权重并尝试预测时,准确率、召回率和准确率都低于 20%。
我在执行过程中做错了吗?
# initial weights of global model, set to zer0.
ave_weights=model.get_weights()
ave_weights=[i * 0 for i in ave_weights]
count=0
# Multithreaded Python server : TCP Server Socket Thread Pool
def ClientThread_send(conn,address,weights):
# send model to client
conn.send(model)
print("Model Sent to :",address)
print("waiting for weights")
model_recv=conn.recv(1024)
print("weights received from:",address)
global count
global ave_weights
#receive weights from clients
rec_weight=model.get_weights()
#multiply the client weights by number of local data samples in client local data
rec_weight= [i * 100000 for i in rec_weight]
# divide the weights by total number of samples of all participants
rec_weight= [i / 200000 for i in rec_weight]
#sum the weights of all clients
ave_weights=[x + y for x, y in zip(ave_weights,rec_weight)]
count=count+1
conn.close()
if count==2:
# set the global model weights if the count(number of clients is two)
model.set_weights(ave_weights)
while True:
conn, address = s.accept()
start_new_thread(ClientThread_send,(conn,address,ave_weights))
【问题讨论】:
标签: python machine-learning artificial-intelligence conv-neural-network tensorflow-federated