This repo is a simple example of how Federated Learning can be implemented using Flower.
In this demo we are going to perform federated learning with flower using a server and two clients.
This code is developed and tested on an ubuntu machine with python 3.8 installed and venv for virtual environment management.
-
Clone the repository by pasting the below command in the terminal.
git clone https://github.com/nclabteam/FL-Demo-With-Flower.git
-
After the repository is cloned, open the cloned repository in terminal.
cd FL-Demo-With-Flower/ -
Ensure pip is installed if not install using
sudo apt install python3-pip
-
We are using venv package to create virtual environent you can use any virtual environment libary to proceed. Run the below command in terminal to install venv.
sudo apt install python3.8-venv
-
Use python venv to create a virtual environment for our project
python3 -m venv venv-flwr-demo
Where "venv-flwr-demo" is the name of the virtual environment that we want to create. We can choose any name that we like instead of venv-flwr-demo. After this step a new directory (venv-flwr-demo) will be created.
-
For using virtual environment we need to activate the environment first.
source venv-flwr-demo/bin/activate -
Now we can install the project requirements or dependencies inside virtual environment using terminal as:
pip3 install -r requirements.txt
-
Open two more terminal windows in the same directory and again activate the virtual env for those terminals also as shown in step 6.
-
In one terminal run the server.py file
python3 server.py
-
Run client1.py in second terminal
python3 client1.py
-
Run client2.py in third terminal
python3 client2.py