Skip to content

Commit

Permalink
remove redundant imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TsingZ0 committed Dec 6, 2023
1 parent 45e310d commit 487a29e
Show file tree
Hide file tree
Showing 52 changed files with 114 additions and 68 deletions.
1 change: 0 additions & 1 deletion dataset/utils/HAR_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

# https://github.com/jindongwang/Deep-learning-activity-recognition/blob/master/pytorch/data_preprocess.py
import numpy as np
import os
import ujson
import numpy as np
import gc
Expand Down
2 changes: 0 additions & 2 deletions system/flcore/clients/clientala.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
import copy
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientapfl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import copy
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientapple.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import copy
import math
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import copy
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
3 changes: 0 additions & 3 deletions system/flcore/clients/clientbabu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import copy
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import torch.nn as nn
import numpy as np
import os
import torch.nn.functional as F
from torch.utils.data import DataLoader
from sklearn.preprocessing import label_binarize
from sklearn import metrics
Expand Down
2 changes: 0 additions & 2 deletions system/flcore/clients/clientbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientditto.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import numpy as np
import time
import copy
import torch.nn as nn
from flcore.optimizers.fedoptimizer import PerturbedGradientDescent
from flcore.clients.clientbase import Client
import torch.nn.functional as F
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientdyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import copy
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientfomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
import copy
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
2 changes: 0 additions & 2 deletions system/flcore/clients/clientlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientmoon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import copy
import torch
import torch.nn as nn
import numpy as np
import time
import torch.nn.functional as F
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientmtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
import math
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientpFedMe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import time
import copy
import torch
import torch.nn as nn
from flcore.optimizers.fedoptimizer import pFedMeOptimizer
from flcore.clients.clientbase import Client

Expand Down
4 changes: 1 addition & 3 deletions system/flcore/clients/clientpcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch.nn.functional as F
import copy
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import time
from collections import defaultdict
Expand Down
3 changes: 0 additions & 3 deletions system/flcore/clients/clientper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import copy
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientperavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import torch
import time
import copy
import torch.nn as nn
from flcore.optimizers.fedoptimizer import PerAvgOptimizer
from flcore.clients.clientbase import Client

Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientphp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import copy
import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
from flcore.clients.clientbase import Client
Expand Down
1 change: 0 additions & 1 deletion system/flcore/clients/clientrod.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import copy
import torch
import torch.nn as nn
import numpy as np
import time
import torch.nn.functional as F
Expand Down
2 changes: 0 additions & 2 deletions system/flcore/clients/clientscaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import torch.nn as nn
import numpy as np
import time
import copy
from flcore.clients.clientbase import Client
from flcore.optimizers.fedoptimizer import SCAFFOLDOptimizer

Expand Down
8 changes: 8 additions & 0 deletions system/flcore/servers/serveramp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def __init__(self, args, times):

print(f"\nJoin ratio / total clients: {self.join_ratio} / {self.num_clients}")
print("Finished creating server and clients.")
self.Budget = []


def train(self):
for i in range(self.global_rounds+1):
s_t = time.time()
self.selected_clients = self.select_clients()
self.send_models()

Expand All @@ -66,13 +69,18 @@ def train(self):
self.call_dlg(i)
self.receive_models()

self.Budget.append(time.time() - s_t)
print('-'*25, 'time cost', '-'*25, self.Budget[-1])

if self.auto_break and self.check_done(acc_lss=[self.rs_test_acc], top_cnt=self.top_cnt):
break

print("\nBest accuracy.")
# self.print_(max(self.rs_test_acc), max(
# self.rs_train_acc), min(self.rs_train_loss))
print(max(self.rs_test_acc))
print("\nAverage time cost per round.")
print(sum(self.Budget[1:])/len(self.Budget[1:]))

self.save_results()

Expand Down
8 changes: 8 additions & 0 deletions system/flcore/servers/serverapfl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import time
from flcore.clients.clientapfl import clientAPFL
from flcore.servers.serverbase import Server
from threading import Thread
Expand All @@ -32,10 +33,12 @@ def __init__(self, args, times):
print("Finished creating server and clients.")

# self.load_model()
self.Budget = []


def train(self):
for i in range(self.global_rounds+1):
s_t = time.time()
self.selected_clients = self.select_clients()
self.send_models()

Expand All @@ -57,13 +60,18 @@ def train(self):
self.call_dlg(i)
self.aggregate_parameters()

self.Budget.append(time.time() - s_t)
print('-'*25, 'time cost', '-'*25, self.Budget[-1])

if self.auto_break and self.check_done(acc_lss=[self.rs_test_acc], top_cnt=self.top_cnt):
break

print("\nBest accuracy.")
# self.print_(max(self.rs_test_acc), max(
# self.rs_train_acc), min(self.rs_train_loss))
print(max(self.rs_test_acc))
print("\nAverage time cost per round.")
print(sum(self.Budget[1:])/len(self.Budget[1:]))

self.save_results()

Expand Down
2 changes: 0 additions & 2 deletions system/flcore/servers/serverapple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import torch
import copy
import random
import time
from flcore.clients.clientapple import clientAPPLE
from flcore.servers.serverbase import Server
Expand Down
8 changes: 8 additions & 0 deletions system/flcore/servers/serverbabu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import time
import random
from flcore.clients.clientbabu import clientBABU
from flcore.servers.serverbase import Server
Expand All @@ -33,10 +34,12 @@ def __init__(self, args, times):
print("Finished creating server and clients.")

# self.load_model()
self.Budget = []


def train(self):
for i in range(self.global_rounds+1):
s_t = time.time()
self.selected_clients = self.select_clients()
self.send_models()

Expand All @@ -58,13 +61,18 @@ def train(self):
self.call_dlg(i)
self.aggregate_parameters()

self.Budget.append(time.time() - s_t)
print('-'*25, 'time cost', '-'*25, self.Budget[-1])

if self.auto_break and self.check_done(acc_lss=[self.rs_test_acc], top_cnt=self.top_cnt):
break

print("\nBest accuracy.")
# self.print_(max(self.rs_test_acc), max(
# self.rs_train_acc), min(self.rs_train_loss))
print(max(self.rs_test_acc))
print("\nAverage time cost per round.")
print(sum(self.Budget[1:])/len(self.Budget[1:]))

for client in self.clients:
client.fine_tune()
Expand Down
1 change: 0 additions & 1 deletion system/flcore/servers/serverbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import copy
import time
import random

from utils.data_utils import read_client_data
from utils.dlg import DLG

Expand Down
9 changes: 8 additions & 1 deletion system/flcore/servers/serverbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import time
from flcore.clients.clientbn import clientBN
from flcore.servers.serverbase import Server
from utils.data_utils import read_client_data
from threading import Thread
import time


class FedBN(Server):
Expand All @@ -34,10 +34,12 @@ def __init__(self, args, times):
print("Finished creating server and clients.")

# self.load_model()
self.Budget = []


def train(self):
for i in range(self.global_rounds+1):
s_t = time.time()
self.selected_clients = self.select_clients()
self.send_models()

Expand All @@ -57,13 +59,18 @@ def train(self):
self.receive_models()
self.aggregate_parameters()

self.Budget.append(time.time() - s_t)
print('-'*25, 'time cost', '-'*25, self.Budget[-1])

if self.auto_break and self.check_done(acc_lss=[self.rs_test_acc], top_cnt=self.top_cnt):
break

print("\nBest accuracy.")
# self.print_(max(self.rs_test_acc), max(
# self.rs_train_acc), min(self.rs_train_loss))
print(max(self.rs_test_acc))
print("\nAverage time cost per round.")
print(sum(self.Budget[1:])/len(self.Budget[1:]))

self.save_results()

Expand Down
1 change: 1 addition & 0 deletions system/flcore/servers/servercp.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def train(self):

print("\nBest global accuracy.")
print(max(self.rs_test_acc))
print("\nAverage time cost per round.")
print(sum(self.Budget[1:])/len(self.Budget[1:]))


Expand Down
Loading

0 comments on commit 487a29e

Please sign in to comment.