This repository contains an implementation of federated learning for a hierarchical approach to behavioral cloning in care robotics. By training locally and exchanging only model weights, we preserve user privacy and achieve competitive performance compared to a non-federated setup.
The project implements a three-tier hierarchy (H1, H2, H3) for robotic control:
- H1 (Classification #1)
- H2 (Classification #2)
- H3 (Regression)
These hierarchies build upon each other, which improves explainability by decomposing the learning process into interpretable stages. Meanwhile, federated learning ensures data stays local, mitigating privacy concerns.
- Create a Conda environment with Python 3.10:
conda create -n fxai_env python=3.10
conda activate fxai_env
- Install Packages wit pip:
pip install -r requirements.txt
-
Download the dataset from Google Drive: Videos_Database_20_Robot_WebCam_50_overall_database.npz
-
Create a folder named
Datain the repository root (if it does not exist). -
Place the downloaded
.npzfile insideData/.
Below is a simplified layout of important files:
.
├── Data
│ └── Videos_Database_20_Robot_WebCam_50_overall_database.npz
├── environment.yml
├── README.md
└── src
├── config
│ └── config.yaml
├── h1.py
├── h2.py
├── h3.py
├── run_all.py
└── utils
├── data_utils.py
├── federated_utils.py
├── logging_utils.py
├── model_h1.py
├── model_h2.py
├── model_h3.py
└── training_utils.py
h1.py,h2.py,h3.py: Each handles the federated learning process for its respective hierarchical model.run_all.py: Script that runs H1 → H2 → H3 in sequence, ensuring each stage starts from the model produced by the previous one.utils/: Contains supporting utilities for data loading, federated setup, logging, and model definitions.config/config.yaml: Hydra configuration specifying model parameters, data paths, etc.
- Edit
config/config.yamlto adjust hyperparameters, paths, or other settings. - Run the entire pipeline:
cd src
python run_all.py
- A timestamped directory will be created under
cfg.paths.output_dir, with subfolders forH1,H2, andH3. - Logs, CSV metrics, and final
.h5models are saved accordingly.
- Check logs in each subfolder to see training progress and final metrics.
To run only one hierarchy, you can execute python h1.py, python h2.py, or python h3.py individually, but note that h2.py and h3.py expect existing model weights from the previous stage.
- Federated Learning: Implemented via TensorFlow Federated (v0.58.0).
- Hierarchical Models:
- H1 learns a first-level classification.
- H2 refines or adds a second-level classification task.
- H3 focuses on regression using the final layer from H2.
- Each subsequent hierarchy loads and adapts the model from the previous stage.
- Explainability: By splitting the modeling task into multiple phases, the internal states (like “phase” or “state”) become more interpretable.
A broader discussion of Federated Learning in Care Robotics, including experimental results and a detailed presentation, is available in a separate repository: Federated-Learning-in-Care-Robotics
Feel free to explore that for in-depth information, additional data, and advanced experimentation details.