Parcourir la source

feat: update readme,remove test log

shellmiao il y a 11 mois
Parent
commit
9ce2381f67
2 fichiers modifiés avec 39 ajouts et 4 suppressions
  1. 39 2
      applications/fedssl/README.md
  2. 0 2
      applications/fedssl/server_with_pgfed.py

+ 39 - 2
applications/fedssl/README.md

@@ -1,15 +1,18 @@
 # Federated Self-supervised Learning (FedSSL)
+
 > 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. 
 
 This repository is the code for two papers:
+
 - 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)
 
-<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:
+
 1. BYOL
 2. SimSiam
 3. MoCo (MoCoV1 & MoCoV2)
@@ -24,6 +27,7 @@ You can conduct training using different FedSSL methods and our proposed FedEMA
 ### FedEMA
 
 Run FedEMA with auto scaler $\tau=0.7$
+
 ```shell
 python applications/fedssl/main.py --task_id fedema --model byol \
       --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$:
+
 ```shell
 python applications/fedssl/main.py --task_id fedema --model byol \
       --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
+
 Run other FedSSL methods: 
+
 ```shell
 python applications/fedssl/main.py --task_id fedbyol --model byol  \
       --aggregate_encoder online --update_encoder online --update_predictor global
 ```
+
 Replace `byol` in `--model byol` with other ssl methods, including `simclr`, `simsiam`, `moco`, `moco_v2` 
 
 ## 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.
 
 ### Linear Evaluation
+
 ```shell
 python applications/fedssl/linear_evaluation.py --dataset cifar10 \
       --model byol --encoder_network resnet18 \
@@ -58,6 +67,7 @@ python applications/fedssl/linear_evaluation.py --dataset cifar10 \
 ```
 
 ### Semi-supervised Evaluation
+
 ```shell
 python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
       --model byol --encoder_network resnet18 \
@@ -67,6 +77,7 @@ python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
 ```
 
 ## File Structure
+
 ```
 ├── client.py <client implementation of federated learning>
 ├── communication.py <constants for model update>
@@ -84,6 +95,32 @@ python applications/fedssl/semi_supervised_evaluation.py --dataset cifar10 \
 └── 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
 
 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},
   publisher={IEEE}
 }
-```
+```

+ 0 - 2
applications/fedssl/server_with_pgfed.py

@@ -70,8 +70,6 @@ class FedSSLWithPgFedServer(FedSSLServer):
         for client in self.grouped_clients:
             client.a_i = self.alpha_mat[client.id]
         if len(self.uploaded_grads) == 0:
-            print(len(self.uploaded_grads))
-            print("uploaded_grads=0")
             return
         self.convex_comb_grad = copy.deepcopy(list(self.uploaded_grads.values())[0])
         for client in self.grouped_clients: