From a96bc7f42d7824c2b88d8406b0e810eb73296130 Mon Sep 17 00:00:00 2001 From: "Daniel J. Beutel" Date: Wed, 24 Jan 2024 12:07:30 +0100 Subject: [PATCH] Format advanced code examples (#2847) --- examples/advanced-pytorch/client.py | 2 +- examples/advanced-pytorch/server.py | 2 +- examples/advanced-pytorch/utils.py | 24 ++++++++++++++---------- examples/advanced-tensorflow/client.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/advanced-pytorch/client.py b/examples/advanced-pytorch/client.py index b22cbcd70465..9958d21136f3 100644 --- a/examples/advanced-pytorch/client.py +++ b/examples/advanced-pytorch/client.py @@ -110,7 +110,7 @@ def main() -> None: ) parser.add_argument( "--toy", - action='store_true', + action="store_true", help="Set to true to quicky run the client using only 10 datasamples. \ Useful for testing purposes. Default: False", ) diff --git a/examples/advanced-pytorch/server.py b/examples/advanced-pytorch/server.py index fda49b71a311..e596e0034164 100644 --- a/examples/advanced-pytorch/server.py +++ b/examples/advanced-pytorch/server.py @@ -76,7 +76,7 @@ def main(): parser = argparse.ArgumentParser(description="Flower") parser.add_argument( "--toy", - action='store_true', + action="store_true", help="Set to true to use only 10 datasamples for validation. \ Useful for testing purposes. Default: False", ) diff --git a/examples/advanced-pytorch/utils.py b/examples/advanced-pytorch/utils.py index 6512010b1f23..872928f0faa1 100644 --- a/examples/advanced-pytorch/utils.py +++ b/examples/advanced-pytorch/utils.py @@ -28,18 +28,21 @@ def load_centralized_data(): def apply_transforms(batch): """Apply transforms to the partition from FederatedDataset.""" - pytorch_transforms = Compose([ - Resize(256), - CenterCrop(224), - ToTensor(), - Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), - ]) + pytorch_transforms = Compose( + [ + Resize(256), + CenterCrop(224), + ToTensor(), + Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), + ] + ) batch["img"] = [pytorch_transforms(img) for img in batch["img"]] return batch -def train(net, trainloader, valloader, epochs, - device: torch.device = torch.device("cpu")): +def train( + net, trainloader, valloader, epochs, device: torch.device = torch.device("cpu") +): """Train the network on the training set.""" print("Starting training...") net.to(device) # move model to GPU if available @@ -71,8 +74,9 @@ def train(net, trainloader, valloader, epochs, return results -def test(net, testloader, steps: int = None, - device: torch.device = torch.device("cpu")): +def test( + net, testloader, steps: int = None, device: torch.device = torch.device("cpu") +): """Validate the network on the entire test set.""" print("Starting evalutation...") net.to(device) # move model to GPU if available diff --git a/examples/advanced-tensorflow/client.py b/examples/advanced-tensorflow/client.py index 033f20b1b027..f42c93784fc6 100644 --- a/examples/advanced-tensorflow/client.py +++ b/examples/advanced-tensorflow/client.py @@ -86,7 +86,7 @@ def main() -> None: ) parser.add_argument( "--toy", - action='store_true', + action="store_true", help="Set to true to quicky run the client using only 10 datasamples. " "Useful for testing purposes. Default: False", )