Fix python3 compatibility issues in the custom algorithms tutorial.
"from __future__ import print_function\n",
"\n",
"import numpy as np\n",
+ "from six.moves import range\n",
"import tensorflow as tf\n",
"\n",
"from tensorflow_federated import python as tff\n",
" 'y': np.array([source[1][i] for i in batch_samples], dtype=np.int32)})\n",
" return output_sequence\n",
"\n",
- "federated_train_data = [get_data_for_digit(mnist_train, d) for d in xrange(10)]\n",
+ "federated_train_data = [get_data_for_digit(mnist_train, d) for d in range(10)]\n",
"\n",
- "federated_test_data = [get_data_for_digit(mnist_test, d) for d in xrange(10)]"
+ "federated_test_data = [get_data_for_digit(mnist_test, d) for d in range(10)]"
]
},
{
"source": [
"model = initial_model\n",
"losses = []\n",
- "for _ in xrange(5):\n",
+ "for _ in range(5):\n",
" model = batch_train(model, sample_batch, 0.1)\n",
" losses.append(batch_loss(model, sample_batch))"
]
"model = initial_model\n",
"learning_rate = 0.1\n",
"losses = []\n",
- "for _ in xrange(5):\n",
+ "for _ in range(5):\n",
" model = federated_train(model, learning_rate, federated_train_data)\n",
" learning_rate = learning_rate * 0.9\n",
" losses.append(federated_eval(model, federated_train_data))"
