Expected a callable, found non-callable tensorflow_federated.python.learning.model_utils.EnhancedTrainableModel

寵の児 提交于 2021-01-28 08:38:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!