This repository implements the Deep Leakage from Gradients (DLG) attack, demonstrating how sensitive training data can be reconstructed from gradients shared during Federated Learning (FL).
- Supports LeNet and ResNet-18 architectures for the attack on CIFAR-10.
- CLI-based workflow for easy experimentation.
- Generates intermediate and final reconstructed images for visualization.
- Python 3.8 or higher
- PyTorch
- torchvision
- matplotlib
-
Clone the repository:
git clone https://github.com/your-username/gradient-inversion-attack.git cd gradient-inversion-attack
-
Install dependencies:
pip install -r requirements.txt
Use main.py
to run the attack via the command line. The script supports the following arguments:
Argument | Type | Default | Description |
---|---|---|---|
--model |
string | None | Specify the model: lenet or resnet . (Required) |
--img_idx |
integer | 25 | Index of the CIFAR-10 image to attack. |
--epochs |
integer | 500 | Number of optimization iterations for the attack. |
To run the attack on LeNet for 500 epochs:
python main.py --model lenet --img_idx 25 --epochs 500
To switch to ResNet:
python main.py --model resnet --img_idx 30 --epochs 1000
- Ground Truth Image: The original CIFAR-10 image selected for the attack, saved as
gt_image.png
in theplots/
directory. - Dummy Image Initialization: Randomly initialized dummy image (
dummy_img.png
). - Reconstructed Images: Saved progressively during the attack (
reconstruction.png
), visualizing the attack's performance.
- LeNet: Successfully reconstructs images in ~300-500 iterations, with results closely matching the ground truth.
- ResNet-18: Reconstruction is more challenging due to the complexity of the model and gradient dispersion but remains feasible under certain conditions.
- Test the attack on deeper models like ResNet-56.
- Experiment with mitigation strategies such as gradient perturbation and compression.
- Extend support for other datasets (e.g., MNIST, ImageNet).
- Understand what works and what doesn't when dealing with deeper models.
- Original Paper: Deep Leakage from Gradients
- Project Insights: Implementation of the DLG attack on CIFAR-10 using LeNet and ResNet.
Star the repo if you find it helpful! 🌟