A comprehensive federated learning implementation that supports MNIST and CIFAR-10 datasets with various FL algorithms, including FedAvg and FedProx.
This project implements a flexible federated learning framework that allows both local and remote training. It features:
- Support for MNIST and CIFAR-10 datasets
- IID and non-IID data distributions
- Multiple federated learning algorithms (FedAvg, FedProx)
- Local and distributed training capabilities
- Web-based dashboard for monitoring training progress
FL/
├── SetupFL/
│ ├── Client/ # Client-side implementation
│ ├── Server/ # Server-side implementation
│ ├── Components/ # Shared components
│ ├── Data/ # Data loading and processing
│ ├── Remote/ # Remote training modules
│ ├── Local/ # Local training modules
│ └── config.yaml # Configuration file
├── requirement.txt # Project dependencies
└── README.md # Project documentation
- Clone the repository
- Create a virtual environment:
python -m venv venv - Activate the virtual environment:
- Windows:
venv\Scripts\activate - Linux/Mac:
source venv/bin/activate
- Windows:
- Install the required packages:
pip install -r requirement.txt
Edit config.yaml to customize:
- Dataset (MNIST, CIFAR-10)
- Model architecture
- Training parameters
- Data distribution (IID or non-IID)
- Federated learning algorithm
Run local federated learning simulation:
python Local/local_test.py --visualize
-
Start the server:
python Remote/remote_test.py -
Start multiple clients (in separate terminals):
python Remote/remote_client.py --client_id 0 --server_url http://localhost:5000 python Remote/remote_client.py --client_id 1 --server_url http://localhost:5000 -
Launch the dashboard:
python Remote/dashboard.py --server_url http://localhost:5000Access the dashboard at http://localhost:8080
To make your federated learning server accessible over the internet (for truly distributed training):
-
Install ngrok from https://ngrok.com/download
-
Add ngrok to your system PATH or navigate to the directory containing the ngrok executable
-
Start your federated learning server:
python Remote/remote_test.py -
In a separate terminal, start ngrok:
ngrok http 5000 -
Ngrok will display a forwarding URL (e.g.,
https://abc123.ngrok-free.app). Use this URL for your remote clients:python Remote/remote_client.py --client_id 0 --server_url "....." -
For the dashboard, also use the ngrok URL:
python Remote/dashboard.py --server_url "....."
Note: The ngrok URL will change each time you restart ngrok unless you have a paid account with a fixed subdomain.
Visualize dataset distribution:
python Data/visualize_data.py
The framework includes:
- CNN for MNIST
- CNN for CIFAR-10
You can modify or extend models in Components/model.py.
Supported federated learning algorithms:
- FedAvg: Standard federated averaging
- FedProx: Federated Proximal focusing on heterogeneity with regularization
The web dashboard provides real-time monitoring of:
- Training progress
- Model accuracy
- Loss curves
- Server status
If you encounter GitHub's file size limit errors with data files:
-
Install Git LFS:
git lfs install -
Track large files:
git lfs track "*.tar.gz" -
Add and commit:
git add .gitattributes git add your-large-file.tar.gz git commit -m "Add large file using Git LFS"
If you encounter Python environment errors:
- Ensure you're using the correct virtual environment
- Try recreating the virtual environment
- Check the Python version (3.7+ recommended)
This project is based on research in federated learning, particularly drawing from:
- "Communication-Efficient Learning of Deep Networks from Decentralized Data" (McMahan et al., 2017)
- "Federated Optimization in Heterogeneous Networks" (Li et al., 2020)