Federated Learning Tensorflow tutorial
Federated Learning Tensorflow tutorial This tutorial demonstrates the usage of Federated Learning with the goal of training a machine learning model with data from different users without having users share their data. The steps are done in a low code environment with the UI and with a Tensorflow framework. Note:This is a step-by-step tutorial for running a UI driven Federated Learning experiment. To see a code sample for an API driven approach, see [Federated Learning Tensorflow samples](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fl-tf2-samples.html). Tip:In this tutorial, admin refers to the user that starts the Federated Learning experiment, and party refers to one or more users who send their model results after the experiment is started by the admin. While the tutorial can be done by the admin and multiple parties, a single user can also complete a full runthrough as both the admin and the party. For a simpler demonstrative purpose, in the following tutorial only one data set is submitted by one party. For more information on the admin and party, see [Terminology](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fl-term.html). Watch this short video tutorial of how to create a Federated Learning experiment with Watson Studio. Video disclaimer: Some minor steps and graphical elements in this video might differ from your platform. This video provides a visual method to learn the concepts and tasks in this documentation. In this tutorial you will learn to: * [Step 1: Start Federated Learning as the admin](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fl-tf2-tutorial.html?context=cdpaas&locale=enstep-1) * [Step 2: Train model as a party](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fl-tf2-tutorial.html?context=cdpaas&locale=enstep-2) * [Step 3: Save and deploy the model online](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fl-tf2-tutorial.html?context=cdpaas&locale=enstep-3) Step 1: Start Federated Learning as the admin In this tutorial, you train a Federated Learning experiment with a Tensorflow framework and the MNIST data set. Before you begin 1. Log in to [IBM Cloud](https://cloud.ibm.com/). If you don't have an account, create one with any email. 2. [Create a Watson Machine Learning service instance](https://cloud.ibm.com/catalog/services/machine-learning) if you do not have it set up in your environment. 3. Log in to [watsonx](https://dataplatform.cloud.ibm.com/home2?context=wx). 4. Use an existing [project](https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/projects.html) or create a new one. You must have at least admin permission. 5. Associate the Watson Machine Learning service with your project. 1. In your project, click the Manage > Service & integrations. 2. Click Associate service. 3. Select your Watson Machine Learning instance from the list, and click Associate; or click New service if you do not have one to set up an instance. ![Screenshot of associating the service](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/fl_tut_add_wml_service.png) Start the aggregator 1. Create the Federated learning experiment asset: 1. Click the Assets tab in your project. 2. Click New asset > Train models on distributed data. 3. Type a Name for your experiment and optionally a description. 4. Verify the associated Watson Machine Learning instance under Select a machine learning instance. If you don't see a Watson Machine Learning instance associated, follow these steps: 1. Click Associate a Machine Learning Service Instance. 2. Select an existing instance and click Associate, or create a New service. 3. Click Reload to see the associated service. ![Screenshot of associating the service](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/fl_demo_2.png) 4. Click Next. 2. Configure the experiment. 1. On the Configure page, select a Hardware specification. 2. Under the Machine learning framework dropdown, select Tensorflow 2. 3. Select a Model type. 4. Download the [untrained model](https://github.com/IBMDataScience/sample-notebooks/raw/master/Files/tf_mnist_model.zip). 5. Back in the Federated Learning experiment, click Select under Model specification. 6. Drag the downloaded file named tf_mnist_model.zip onto the Upload file box.1. Select runtime-22.2-py3.10 for the Software Specification dropdown. 7. Give your model a name, and then click Add. ![Screenshot of importing an initial model](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/fl_demo_3.png) 8. Click Weighted average for the Fusion method, and click Next. ![Screenshot of Fusion methods UI](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/fl_demo_4.png) 3. Define the hyperparameters. 1. Accept the default hyperparameters or adjust as needed. 2. When you are finished, click Next. 4. Select remote training systems. 1. Click Add new systems. ![Screenshot of Add RTS UI](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/fl_demo_7.png) 2. Give your Remote Training System a name. 3. Under Allowed identities, choose the user that is your party, and then click Add. In this tutorial, you can add a dummy user or yourself, for demonstrative purposes. This user must be added to your project as a collaborator with Editor or higher permissions. Add additional systems by repeating this step for each remote party you intent to use. 4. When you are finished, click Add systems. ![Screenshot of adding users](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/images/fl_demo_8.png) 5. Return to the Select remote training systems page, verify that your system is selected, and then click Next. 5. Review your settings, and then click Create. 6. Watch the status. Your Federated Learning experiment status is Pending when it starts. When your experiment is ready for parties to connect, the status will change to Setup – Waiting for remote systems. This may take a few minutes. 7. Click View setup information to download the party configuration and the party connector script that can be run on the remote party. 8. Click the