-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(baselines) Update FedRep baseline (#4681)
Co-authored-by: jafermarq <[email protected]>
- Loading branch information
1 parent
d7ebf97
commit 76809af
Showing
29 changed files
with
756 additions
and
1,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
algorithm = "fedrep" | ||
|
||
# model specs | ||
model-name = "cnncifar100" | ||
|
||
# dataset specs | ||
dataset-name = "cifar100" | ||
dataset-split = "sample" | ||
dataset-split-num-classes = 20 | ||
dataset-split-seed = 42 | ||
dataset-split-fraction = 0.83 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
algorithm = "fedrep" | ||
|
||
# model specs | ||
model-name = "cnncifar100" | ||
|
||
# dataset specs | ||
dataset-name = "cifar100" | ||
dataset-split = "sample" | ||
dataset-split-num-classes = 5 | ||
dataset-split-seed = 42 | ||
dataset-split-fraction = 0.83 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
algorithm = "fedrep" | ||
|
||
# dataset specs | ||
dataset-name = "cifar10" | ||
dataset-split = "sample" | ||
dataset-split-num-classes = 2 | ||
dataset-split-seed = 42 | ||
dataset-split-fraction = 0.83 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
algorithm = "fedrep" | ||
|
||
# dataset specs | ||
dataset-name = "cifar10" | ||
dataset-split = "sample" | ||
dataset-split-num-classes = 5 | ||
dataset-split-seed = 42 | ||
dataset-split-fraction = 0.83 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Generate plots from json files.""" | ||
|
||
import json | ||
import os | ||
from typing import List, Tuple | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
# Get the current working directory | ||
DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
def read_from_results(path: str) -> Tuple[str, str, List[float], str, str]: | ||
"""Load the json file with recorded configurations and results.""" | ||
with open(path, "r", encoding="UTF-8") as fin: | ||
data = json.load(fin) | ||
algorithm = data["run_config"]["algorithm"] | ||
model = data["run_config"]["model-name"] | ||
accuracies = [res["accuracy"] * 100 for res in data["round_res"]] | ||
dataset = data["run_config"]["dataset-name"] | ||
num_classes = data["run_config"]["dataset-split-num-classes"] | ||
|
||
return algorithm, model, accuracies, dataset, num_classes | ||
|
||
|
||
def make_plot(dir_path: str, plt_title: str) -> None: | ||
"""Given a directory with json files, generated a plot using the provided title.""" | ||
plt.figure() | ||
with os.scandir(dir_path) as files: | ||
for file in files: | ||
file_name = os.path.join(dir_path, file.name) | ||
print(file_name, flush=True) | ||
algo, m, acc, d, n = read_from_results(file_name) | ||
rounds = [i + 1 for i in range(len(acc))] | ||
print(f"Max accuracy ({algo}): {max(acc):.2f}") | ||
plt.plot(rounds, acc, label=f"{algo}-{d}-{n}classes") | ||
plt.xlabel("Rounds") | ||
plt.ylabel("Accuracy") | ||
plt.title(plt_title) | ||
plt.grid() | ||
plt.legend() | ||
plt.savefig(os.path.join(DIR, f"{plt_title}-{algo}")) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Plot results generated by the baseline. | ||
# Combine them into a full file path. | ||
res_dir = os.path.join(DIR, "../results/") | ||
title = "Federated Accuracy over Rounds" | ||
make_plot(res_dir, plt_title=title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"""Template baseline package.""" | ||
"""fedrep: A Flower Baseline.""" |
Oops, something went wrong.