Пример #1
0
def local_eval(model, all_batches):
    # TODO: Replace with `tff.sequence_average` once implemented
    return tff.sequence_sum(
        tff.sequence_map(
            tff.federated_computation(lambda b: batch_loss(model, b),
                                      BATCH_TYPE), all_batches))
Пример #2
0
import tensorflow as tf
from tensorflow.python.keras.optimizer_v2 import gradient_descent
from tensorflow_federated import python as tff
from matplotlib import pyplot as plt
"""
Simple process
Step 1: Create a set of federeted data to feed to TFF model
Step 2: Create a trainable TFF model by wrapping a Keras model
Step 3: Train TFF model with federated data
"""

# Set up environment
nest = tf.contrib.framework.nest
np.random.seed(0)
tf.compat.v1.enable_v2_behavior()
print(tff.federated_computation(lambda: 'Hello, World!')())

#@test {"output": "ignore"}

# Load EMNIST dataset
emnist_train, emnist_test = tff.simulation.datasets.emnist.load_data()

print(len(emnist_train.client_ids), emnist_train.output_shapes,
      emnist_train.output_types)

# Sample data for a client
example_dataset = emnist_train.create_tf_dataset_for_client(
    emnist_train.client_ids[0])
example_element = iter(example_dataset).next()
print(example_element['label'].numpy())
Пример #3
0
from six.moves import range
import numpy as np
import tensorflow as tf
from tensorflow.python.keras.optimizer_v2 import gradient_descent
try:
    from tensorflow_federated import python as tff
except:
    get_ipython().system('pip install -q tensorflow_federated')

nest = tf.contrib.framework.nest

np.random.seed(0)

tf.compat.v1.enable_v2_behavior()

tff.federated_computation(lambda: 'Its, Working!')()

# In[3]:

#@test {"output": "ignore"}
emnist_train, emnist_test = tff.simulation.datasets.emnist.load_data()

# In[4]:

len(emnist_train.client_ids)

# In[5]:

emnist_train.output_types, emnist_train.output_shapes

# In[6]: