Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format advanced-pytorch and advanced-tensorflow code examples #2847

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/advanced-pytorch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced-pytorch/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
24 changes: 14 additions & 10 deletions examples/advanced-pytorch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced-tensorflow/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down