This repository contains the code to set up a federated learning system using a Raspberry Pi as the client. Federated learning allows multiple devices to collaboratively learn a shared model while keeping the training data on the device.
client/: Contains the code for the Raspberry Pi client.server/: Contains the code for the central server that coordinates federated learning.README.md: This file, providing an overview and setup instructions for the project.
- Python 3.7+
- TensorFlow or PyTorch
flwr(Flower framework for federated learning)
- Raspberry Pi (preferably the latest model)
client/requirements.txt: Required Python packages for the client
- Sufficient computational resources to run the federated learning server
server/requirements.txt: Required Python packages for the server
- Navigate to the
server/directory. - Install the required packages:
pip install -r requirements.txt
- Run the server:
python server.py
- Navigate to the
client/directory. - Install the required packages:
pip install -r requirements.txt
- Run the client:
python client.py
SERVER_ADDRESS: The address of the federated learning server.DATASET_PATH: The path to the dataset used by the client.
SERVER_ADDRESS: The address for the federated learning server to listen on.
setup_logging(log_file="server.log"): Sets up logging to a file and console.log_info(message): Logs an informational message.log_error(message): Logs an error message.save_model(model, model_dir="models", model_name="model.h5"): Saves the model to the specified directory.load_model(model_dir="models", model_name="model.h5"): Loads the model from the specified directory.save_config(config, config_path="config.json"): Saves the configuration to a JSON file.load_config(config_path="config.json"): Loads the configuration from a JSON file.
- Start the Server: Ensure the server is running on a machine with sufficient resources.
- Start the Client: Run the client script on the Raspberry Pi.
- The server and client will communicate to perform federated learning.
cd server/
pip install -r requirements.txt
python server.py