|
@@ -1,15 +1,18 @@
|
|
# Federated Self-supervised Learning (FedSSL)
|
|
# Federated Self-supervised Learning (FedSSL)
|
|
|
|
+
|
|
> Also name as Federated Unsupervised Representation Learning (FedU)
|
|
> Also name as Federated Unsupervised Representation Learning (FedU)
|
|
|
|
|
|
A common limitation of existing federated learning (FL) methods is that they heavily rely on data labels on decentralized clients. We propose federated self-supervised learning framework (FedSSL) to learn visual representations from decentralized data without labels.
|
|
A common limitation of existing federated learning (FL) methods is that they heavily rely on data labels on decentralized clients. We propose federated self-supervised learning framework (FedSSL) to learn visual representations from decentralized data without labels.
|
|
|
|
|
|
This repository is the code for two papers:
|
|
This repository is the code for two papers:
|
|
|
|
+
|
|
- Divergence-aware Federated Self-Supervised Learning, _ICLR'2022_. [[paper]](https://openreview.net/forum?id=oVE1z8NlNe)
|
|
- Divergence-aware Federated Self-Supervised Learning, _ICLR'2022_. [[paper]](https://openreview.net/forum?id=oVE1z8NlNe)
|
|
- Collaborative Unsupervised Visual Representation Learning From Decentralized Data, _ICCV'2021_. [[paper]](https://openaccess.thecvf.com/content/ICCV2021/html/Zhuang_Collaborative_Unsupervised_Visual_Representation_Learning_From_Decentralized_Data_ICCV_2021_paper.html)
|
|
- Collaborative Unsupervised Visual Representation Learning From Decentralized Data, _ICCV'2021_. [[paper]](https://openaccess.thecvf.com/content/ICCV2021/html/Zhuang_Collaborative_Unsupervised_Visual_Representation_Learning_From_Decentralized_Data_ICCV_2021_paper.html)
|
|
|
|
|
|
-<img src="images/fedssl.png" width="700">
|
|
|
|
|
|
+<img src="C:\Program Files\Typora\images\fedssl.png" width="700">
|
|
|
|
|
|
The framework implements four self-supervised learning (SSL) methods based on Siamese networks in the federated manner:
|
|
The framework implements four self-supervised learning (SSL) methods based on Siamese networks in the federated manner:
|
|
|
|
+
|
|
1. BYOL
|
|
1. BYOL
|
|
2. SimSiam
|
|
2. SimSiam
|
|
3. MoCo (MoCoV1 & MoCoV2)
|
|
3. MoCo (MoCoV1 & MoCoV2)
|
|
@@ -24,6 +27,7 @@ You can conduct training using different FedSSL methods and our proposed FedEMA
|
|
### FedEMA
|
|
### FedEMA
|
|
|
|
|
|
Run FedEMA with auto scaler $\tau=0.7$
|
|
Run FedEMA with auto scaler $\tau=0.7$
|
|
|
|
+
|
|
```shell
|
|
```shell
|
|
python applications/fedssl/main.py --task_id fedema --model byol \
|
|
python applications/fedssl/main.py --task_id fedema --model byol \
|
|
--aggregate_encoder online --update_encoder dynamic_ema_online --update_predictor dynamic_dapu \
|
|
--aggregate_encoder online --update_encoder dynamic_ema_online --update_predictor dynamic_dapu \
|
|
@@ -31,6 +35,7 @@ python applications/fedssl/main.py --task_id fedema --model byol \
|
|
```
|
|
```
|
|
|
|
|
|
Run FedEMA with constant weight scaler $\lambda=1$:
|
|
Run FedEMA with constant weight scaler $\lambda=1$:
|
|
|
|
+
|
|
```shell
|
|
```shell
|
|
python applications/fedssl/main.py --task_id fedema --model byol \
|
|
python applications/fedssl/main.py --task_id fedema --model byol \
|
|
--aggregate_encoder online --update_encoder dynamic_ema_online --update_predictor dynamic_dapu \
|
|
--aggregate_encoder online --update_encoder dynamic_ema_online --update_predictor dynamic_dapu \
|
|
@@ -38,11 +43,14 @@ python applications/fedssl/main.py --task_id fedema --model byol \
|
|
```
|
|
```
|
|
|
|
|
|
### Other SSL methods
|
|
### Other SSL methods
|
|
|
|
+
|
|
Run other FedSSL methods:
|
|
Run other FedSSL methods:
|
|
|
|
+
|
|
```shell
|
|
```shell
|
|
python applications/fedssl/main.py --task_id fedbyol --model byol \
|
|
python applications/fedssl/main.py --task_id fedbyol --model byol \
|
|
--aggregate_encoder online --update_encoder online --update_predictor global
|
|
--aggregate_encoder online --update_encoder online --update_predictor global
|
|
```
|
|
```
|
|
|
|
+
|
|
Replace `byol` in `--model byol` with other ssl methods, including `simclr`, `simsiam`, `moco`, `moco_v2`
|
|
Replace `byol` in `--model byol` with other ssl methods, including `simclr`, `simsiam`, `moco`, `moco_v2`
|
|
|
|
|
|
## Evaluation
|
|
## Evaluation
|
|
@@ -50,6 +58,7 @@ Replace `byol` in `--model byol` with other ssl methods, including `simclr`, `si
|
|
You can evaluate the saved model with either linear evaluation and semi-supervised evaluation.
|
|
You can evaluate the saved model with either linear evaluation and semi-supervised evaluation.
|
|
|
|
|
|
### Linear Evaluation
|
|
### Linear Evaluation
|
|
|
|
+
|
|
```shell
|
|
```shell
|
|
python applications/fedssl/linear_evaluation.py --dataset cifar10 \
|
|
python applications/fedssl/linear_evaluation.py --dataset cifar10 \
|
|
--model byol --encoder_network resnet18 \
|
|
--model byol --encoder_network resnet18 \
|
|
@@ -58,6 +67,7 @@ python applications/fedssl/linear_evaluation.py --dataset cifar10 \
|
|
```
|
|
```
|
|
|
|
|
|
### Semi-supervised Evaluation
|
|
### Semi-supervised Evaluation
|
|
|
|
+
|
|
```shell
|
|
```shell
|
|
python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
|
|
python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
|
|
--model byol --encoder_network resnet18 \
|
|
--model byol --encoder_network resnet18 \
|
|
@@ -67,6 +77,7 @@ python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
|
|
```
|
|
```
|
|
|
|
|
|
## File Structure
|
|
## File Structure
|
|
|
|
+
|
|
```
|
|
```
|
|
├── client.py <client implementation of federated learning>
|
|
├── client.py <client implementation of federated learning>
|
|
├── communication.py <constants for model update>
|
|
├── communication.py <constants for model update>
|
|
@@ -84,6 +95,32 @@ python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
|
|
└── utils.py
|
|
└── utils.py
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+## With PGFed
|
|
|
|
+
|
|
|
|
+使用参数--use_pgfed控制训练过程是否使用PGFed
|
|
|
|
+
|
|
|
|
+### 当前可用范围
|
|
|
|
+
|
|
|
|
+针对四种SSL方法(SimCLR,MoCo,BYOL和SimSiam),其中由于BYOL(实测)、MoCo(未测试,但是代码是这样写的)没有使用pytorch的梯度更新,需要后续再单独做适配。而SimCLR(实测)以及SimSiam(未测试,看代码ok)可直接运行。
|
|
|
|
+
|
|
|
|
+### PGFed相关参数设置
|
|
|
|
+
|
|
|
|
+lambdaa = 1.0
|
|
|
|
+
|
|
|
|
+mu = 0
|
|
|
|
+
|
|
|
|
+momentum = 0.0
|
|
|
|
+
|
|
|
|
+硬编码,需要可自行设置
|
|
|
|
+
|
|
|
|
+(没有设置动量更新的Flag,momentum = 0.0 即代表不使用动量更新)
|
|
|
|
+
|
|
|
|
+### 针对自监督学习的改动
|
|
|
|
+
|
|
|
|
+![image-20240110235132811](https://shellmia0-blog-1304113800.cos.ap-beijing.myqcloud.com/image-20240110235132811.png)
|
|
|
|
+
|
|
|
|
+更新方式改为自监督学习更新方式
|
|
|
|
+
|
|
## Citation
|
|
## Citation
|
|
|
|
|
|
If you use these codes in your research, please cite these projects.
|
|
If you use these codes in your research, please cite these projects.
|
|
@@ -112,4 +149,4 @@ If you use these codes in your research, please cite these projects.
|
|
year={2022},
|
|
year={2022},
|
|
publisher={IEEE}
|
|
publisher={IEEE}
|
|
}
|
|
}
|
|
-```
|
|
|
|
|
|
+```
|