Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Federated Learning with Python

You're reading from   Federated Learning with Python Design and implement a federated learning system and develop applications using existing frameworks

Arrow left icon
Product type Paperback
Published in Oct 2022
Publisher Packt
ISBN-13 9781803247106
Length 326 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Authors (2):
Arrow left icon
George Jeno George Jeno
Author Profile Icon George Jeno
George Jeno
Kiyoshi Nakayama, PhD Kiyoshi Nakayama, PhD
Author Profile Icon Kiyoshi Nakayama, PhD
Kiyoshi Nakayama, PhD
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1 Federated Learning – Conceptual Foundations
2. Chapter 1: Challenges in Big Data and Traditional AI FREE CHAPTER 3. Chapter 2: What Is Federated Learning? 4. Chapter 3: Workings of the Federated Learning System 5. Part 2 The Design and Implementation of the Federated Learning System
6. Chapter 4: Federated Learning Server Implementation with Python 7. Chapter 5: Federated Learning Client-Side Implementation 8. Chapter 6: Running the Federated Learning System and Analyzing the Results 9. Chapter 7: Model Aggregation 10. Part 3 Moving Toward the Production of Federated Learning Applications
11. Chapter 8: Introducing Existing Federated Learning Frameworks 12. Chapter 9: Case Studies with Key Use Cases of Federated Learning Applications 13. Chapter 10: Future Trends and Developments 14. Index 15. Other Books You May Enjoy Appendix: Exploring Internal Libraries

Aggregating local models

The aggregation.py code handles aggregating local models with a bunch of aggregation algorithms. In the code example, we only support FedAvg, as discussed in the following sections.

Importing the libraries for the aggregator

The aggregation.py code imports the following:

import logging
import time
import numpy as np
from typing import List
from .state_manager import StateManager
from fl_main.lib.util.helpers import generate_model_id
from fl_main.lib.util.states import IDPrefix

The imported state manager’s role and functionalities are discussed in the Maintaining models for aggregation with the state manager section, and the helpers and states libraries are introduced in the Appendix, Exploring Internal Libraries.

After importing the necessary libraries, let’s define the aggregator class.

Defining and initializing the aggregator class

The following code for class Aggregator defines the core process of the aggregator, which...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image