(solved) Tensorflow Federated | Tff.learning.from_keras_model() With A Model With Densefeature Layer And Multiple Inputs
I'm trying to federate a keras model which has multiple inputs. These some of these inputs are categorical and some of them are numerical, so I have some DenseFeature layers to emb
Solution 1:
I was able to find the answer looking at the Federate Learning repository on GitHub:
The way to do it is to make the 'x' value of the orderedDict an orderedDict itself using as keys the name of the columns we want as input.
A concrete example is given here: https://github.com/tensorflow/federated/blob/3b5a551c46e7eab61e40c943390868fca6422e21/tensorflow_federated/python/learning/keras_utils_test.py#L283
Where it define the input spec:
input_spec = collections.OrderedDict(
x=collections.OrderedDict(
a=tf.TensorSpec(shape=[None, 1], dtype=tf.float32),
b=tf.TensorSpec(shape=[1, 1], dtype=tf.float32)),
y=tf.TensorSpec(shape=[None, 1], dtype=tf.float32))
model = model_examples.build_multiple_inputs_keras_model()
To be used in the model defined as:
defbuild_multiple_inputs_keras_model():
"""Builds a test model with two inputs."""
l = tf.keras.layers
a = l.Input((1,), name='a')
b = l.Input((1,), name='b')
# Each input has a single, independent dense layer, which are combined into# a final dense layer.
output = l.Dense(1)(
l.concatenate([
l.Dense(1)(a),
l.Dense(1)(b),
]))
return tf.keras.Model(inputs={'a': a, 'b': b}, outputs=[output])
Post a Comment for "(solved) Tensorflow Federated | Tff.learning.from_keras_model() With A Model With Densefeature Layer And Multiple Inputs"