Fixes OpenMined Conference 2020 TFF tutorial notebook
"import numpy as np\n",
"import tensorflow as tf\n",
"import tensorflow_federated as tff\n",
- "from skimage import io\n",
"\n",
"tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n",
"\n",
},
"outputs": [],
"source": [
- "# Code for loading federated data from TFF repository\n"
+ "# Code for loading federated data from TFF repository\n",
+ "emnist_train, emnist_test = tff.simulation.datasets.emnist.load_data()"
]
},
{
"example_dataset = emnist_train.create_tf_dataset_for_client(\n",
" emnist_train.client_ids[0])\n",
"\n",
- "# Your code to get an example element from one client:\n"
+ "# Your code to get an example element from one client:\n",
+ "example_element = next(iter(example_dataset))\n",
+ "\n",
+ "example_element['label'].numpy()"
]
},
{
"sample_clients = emnist_train.client_ids[0:NUM_CLIENTS]\n",
"\n",
"# Your code to get the federated dataset here for the sampled clients:\n",
- "\n",
+ "federated_train_data = make_federated_data(emnist_train, sample_clients)\n",
"\n",
"print('Number of client datasets: {l}'.format(l=len(federated_train_data)))\n",
"print('First dataset: {d}'.format(d=federated_train_data[0]))"
" model_fn,\n",
" client_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=0.02),\n",
" # Add server optimizer here!\n",
+ " server_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=1.0))\n",
" "
]
},
" shutil.rmtree(logdir)\n",
"\n",
"# Your code to create a summary writer:\n",
- "\n",
+ "summary_writer = tf.summary.create_file_writer(logdir)\n",
"\n",
"state = iterative_process.initialize()"
]
