A repo to show the visual comparison between different federated learning algorithms. This is the official repo for our paper on An Analysis of Personalized Federated Learning Algorithms with an Intuitive Protected Model Training
Click to expand
- FedAvg
- FedProto
- FedBABU
- APPLE
- OS: Windows (Tested on Windows 10 21H2), Linux (Arch Linux 2023.4.1)
- Python 3.10.9
pip --verison:
|--- dataset
|--- logs
|--- results
|--- system
| |--- models
| |--- utils
| |--- main.py
|--- venv
|--- requirements.txt
The FMNIST dataset and the algorithms operating on the dataset is implemented inside this directory. The base code & inspiration is taken from the PFL-NON-IID repo. The code is modified to work with our project structure with added support for logging, visualization, and more. Currently the algorithms implemented inside the this directory are:
- FedAvg
- FedProto
- FedBABU
- APPLE
There is requirements.txt file for all the algorithms inside this directory. First of all activate the virtual environment. Then run the following command:
pip install -r requirements.txtThe main script has to be run from the system directory. The main script is main.py and it is located inside this directory. The main script has the following arguments:
python main.py -data fmnist -m cnn -algo FedAvg -gr 10 -did 0 -go cnn -nc 1-data: The dataset to use. Currently onlyfmnistis supported.-m: The model to use. Currently onlycnnis supported.-algo: The algorithm to use. Currently onlyFedAvg,FedProto,FedBABU, andAPPLEare supported.-gr: The number of global rounds to run the algorithm.-did: The device id. This is used to differentiate between different devices. This is used for logging purposes.-go: The global optimizer to use. Currently onlycnnis supported.-nc: The number of clients to use. Currently the maximum number of clients supported is 20. (Tested on core-i9 machine)
So to run different algorithms on the FMNIST dataset, you just have to change the -algo argument. For example, to run the FedProto algorithm, you have to run the following command:
python main.py -data fmnist -m cnn -algo FedProto -gr 10 -did 0 -go cnn -nc 1I have added a Makefile to run the algorithms. The Makefile is located inside this directory. The Makefile has the following commands:
make run: Run the main script with the default argumentsmake config: Makes sure that all the needed directories are created & packages are installed and then check if thevenvis activated or not. If not, then activate thevenv.make clean: Clean thevenvand the__pycache__directories & other unwanted files/directories.
The make run command runs the main script with the following arguments:
make run DATA=Cifar10 GR=3 NC=1 ALGO=FedAvgHere the DATA argument is the dataset to use, the GR argument is the number of global rounds to run the algorithm, the NC argument is the number of clients to use, and the ALGO argument is the algorithm to use. The DATA argument is required, the GR argument is optional and the default value is 3, the NC argument is optional and the default value is 1, and the ALGO argument is optional and the default value is FedAvg.
The generated images and the execution logs are saved in separate directories. The images are saved in the results directory and the logs are saved in the logs directory.
- Used the MNIST dataset from TensorFlow Datasets
- Used the Flower library for federated learning
- Used the fedavg_mnist example code for the FedAvg algorithm implementation. The code is modified to work with the MNIST dataset. Couldn't fork the specific directory so I copied the code and modified it.
- Used the PFL-NON-IID repo for the FMNIST dataset and the algorithms operating on the dataset.