Yangfan-Jiang / Federated-Learning-with-Differential-Privacy

Implementation of dp-based federated learning framework using PyTorch
MIT License
289 stars 56 forks source link

some questions about CDP #8

Open lq1029 opened 1 year ago

lq1029 commented 1 year ago

I meet some trouble when I apply differential privacy into FL in the way of CDP.Specifically,I add noise during aggregated stage in server, and then broadcast to all client. However, the finally accuracy result is low…… I'd be appreciated it if you could do me some favor.

lq1029 commented 1 year ago

also,i get some trouble when i attempt to calculate the loss, such as the value is so big(ten thousand……), and doesn't converge, but the acc is normal. def test_acc(self): self.global_model.eval() correct = 0 tot_sample = 0 total_loss = 0 criterion = nn.CrossEntropyLoss(reduction='sum')

    for i in range(len(self.data)):
        t_pred_y = self.global_model(self.data[i])
        _, predicted = torch.max(t_pred_y, 1)
        correct += (predicted == self.target[i]).sum().item()
        tot_sample += self.target[i].size(0)

        loss = criterion(t_pred_y, self.target[i].long())
        total_loss += loss.item()  

    acc = correct / tot_sample
    avg_loss = total_loss / len(self.data)
    return acc, avg_loss