From 9eb669fa41101d5877f1ebc68a50f3f934cf3171 Mon Sep 17 00:00:00 2001 From: mattiasakesson Date: Tue, 26 Sep 2023 17:28:49 +0200 Subject: [PATCH] add android helper functionality --- .../network/dashboard/templates/context.html | 2 ++ fedn/fedn/utils/plugins/androidhelper.py | 32 +++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/fedn/fedn/network/dashboard/templates/context.html b/fedn/fedn/network/dashboard/templates/context.html index 8f392082a..d106f9ade 100644 --- a/fedn/fedn/network/dashboard/templates/context.html +++ b/fedn/fedn/network/dashboard/templates/context.html @@ -14,6 +14,8 @@
{{ message }}
diff --git a/fedn/fedn/utils/plugins/androidhelper.py b/fedn/fedn/utils/plugins/androidhelper.py index 71a293ab4..c78849115 100644 --- a/fedn/fedn/utils/plugins/androidhelper.py +++ b/fedn/fedn/utils/plugins/androidhelper.py @@ -6,33 +6,33 @@ class Helper(HelperBase): - """ FEDn helper class for keras.Sequential. """ + """ FEDn helper class for android json model weights. """ def __init__(self): """ Initialize helper. """ - self.name = "kerashelper" + self.name = "androidhelper" super().__init__() # function to calculate an incremental weighted average of the weights def increment_average(self, model, model_next, num_examples, total_examples): """ Incremental weighted average of model weights. - :param model: Current model weights. - :type model: list of numpy arrays. - :param model_next: New model weights. - :type model_next: list of numpy arrays. - :param num_examples: Number of examples in new model. - :type num_examples: int - :param total_examples: Total number of examples. - :type total_examples: int - :return: Incremental weighted average of model weights. - :rtype: list of numpy arrays. - """ + :param model: Current model weights. + :type model: list of numpy arrays. + :param model_next: New model weights. + :type model_next: list of numpy arrays. + :param num_examples: Number of examples in new model. + :type num_examples: int + :param total_examples: Total number of examples. + :type total_examples: int + :return: Incremental weighted average of model weights. + :rtype: list of numpy arrays. + """ # Incremental weighted average w = num_examples / total_examples - weights = [] - for i in range(len(model)): - weights.append(w * model[i] + (1 - w) * model_next[i]) + weights = {} + for i in model.keys(): + weights[i] = list(w * np.array(model[i]) + (1 - w) * np.array(model_next[i])) return weights