Federated Unsupervised Domain Generalization Using Global and Local Alignment of Gradients
FedGaLA is a novel framework for federated unsupervised domain generalization, combining global and local gradient alignment to enhance model generalization across diverse domains while preserving privacy. This repository contains the official implementation of FedGaLA as described in our paper published in AAAI 2025.
- Federated Learning Framework: Incorporates both server-level (global) and client-level (local) gradient alignment techniques.
- Domain Generalization: Designed to handle multi-domain datasets under privacy constraints.
- Flexible Self-Supervised Learning (SSL) Backbones: Supports
byol
,simsiam
,moco
, andsimclr
SSL methods. - Ease of Use: Simple and modular implementation for easy experimentation and adaptation.
For the full paper see here.
Follow these steps to set up your environment and train models:
- Install Dependencies
Use the following command to install all required Python packages:pip install -r requirements.txt
- Download Datasets Use the links provided in the Data section. Extract the datasets into the ./data folder (or a directory of your choice).
- Choose an SSL Method Select a Self-Supervised Learning method from byol, simsiam, moco, or simclr.
- Train Baseline Models To train a baseline model (e.g., FedSimCLR on the PACS dataset), use the following command:
python main.py --test_domain s --dataset pacs --dataroot ./data/PACS --labeled_ratio 0.1 \
--communication_rounds 100 --client_epoch 7 --backbone resnet18 --aggregation FedAVG \
--SSL simclr --workers 2
- Train FedGaLA Use the following command to train the FedGaLA model:
python main.py --test_domain s --dataset pacs --dataroot ./data/PACS --labeled_ratio 0.1 \
--communication_rounds 100 --client_epoch 7 --backbone resnet18 --aggregation GA \
--SSL simclr --client_gm LA --local_threshold 0.0 --gamma 0.00 --workers 2
GA
: Global Alignment (server-level).LA
: Local Alignment (client-level).Default aggregation
: FedAVG (if aggregation is not specified).--workers
0 (For Windows users)
FedGaLA supports the following datasets:
For the PACS dataset, please download this csv file and place it in the designated directory.
Please download and extract them to the ./data
directory or a directory you choose, then change the --dataroot
argument to that directory.
If you find this work useful, please consider citing:
@article{FedGaLA2025,
title={Federated Unsupervised Domain Generalization Using Global and Local Alignment of Gradients},
author={Pourpanah, Farhad and Molahasani, Mahdiyar and Soltany, Milad and Greenspan, Michael and Etemad, Ali},
journal={AAAI},
year={2025}
}
@article{FedDG2024,
title={A Theoretical Framework for Federated Domain Generalization with Gradient Alignment},
author={Molahasani, Mahdiyar and Soltany, Milad and Pourpanah, Farhad and Greenspan, Michael and Etemad, Ali},
journal={NeurIPS Workshop on Mathematics of Modern Machine Learning},
year={2024}
}
This project is licensed under the MIT License.
Feel free to check out our GitHub profiles for more of our work!
Contributions are welcome! Please open an issue or submit a pull request for any improvements, features, or bug fixes.
For questions or inquiries, please reach out to m.molahasani@queensu.ca.
Happy experimenting with FedGaLA!