问题
Unable to use TFF's build_federated_averaging_process(). Followed the tutorial from the TFF federated documentation.
Here's my model code:
X_train = <valuex>
Y_train = <valuey>
def model_fn():
model = tf.keras.models.Sequential([
tf.keras.layers.Conv1D(32,dtype="float64",kernel_size=3,padding='same',activation=tf.nn.relu,input_shape=(X_train.shape[1], X_train.shape[2])),
tf.keras.layers.MaxPooling1D(pool_size=3),
tf.keras.layers.Conv1D(64,kernel_size=3,padding='same',activation=tf.nn.relu),
tf.keras.layers.MaxPooling1D(pool_size=3),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128,activation=tf.nn.relu),
tf.keras.layers.Dropout(0.45),
tf.keras.layers.Dense(1, activation=tf.nn.sigmoid)
])
model.compile(
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
optimizer=tf.keras.optimizers.SGD(learning_rate=0.05),
metrics=[tf.keras.metrics.Accuracy()])
model.summary()
return tff.learning.from_compiled_keras_model(model, sample_batch)
iterative_process = tff.learning.build_federated_averaging_process(model_fn())
I get the error:
TypeError: Expected a callable, found non-callable tensorflow_federated.python.learning.model_utils.EnhancedTrainableModel.
回答1:
The argument to build_federated_averaging_process
should be the model_fn
function, not the return value from invoking it.
Try changing this line:
iterative_process = tff.learning.build_federated_averaging_process(model_fn())
to:
iterative_process = tff.learning.build_federated_averaging_process(model_fn)
来源:https://stackoverflow.com/questions/57381329/expected-a-callable-found-non-callable-tensorflow-federated-python-learning-mod