Issue
I have a dataset with numeric features and labels. I am building a federated learning model using TensorFlow (TFF).
Basically, the model that I have is the (neural network) which is always explained in the TFF tutorials.
I want to ask if there is a chance to build another model for the local clients, such as SVM? since it suits my dataset.
My neural network:
def create_keras_model():
initializer = tf.keras.initializers.Zeros()
return tf.keras.models.Sequential([
tf.keras.layers.Input(shape=(18,)),
tf.keras.layers.Dense(128),
tf.keras.layers.Dense(4, kernel_initializer= initializer),
tf.keras.layers.Softmax(),
])
def model_fn():
keras_model = create_keras_model()
return tff.learning.from_keras_model(
keras_model,
input_spec=train_data[0].element_spec,
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
metrics=[tf.keras.metrics.SparseCategoricalAccuracy()]
)
Solution
TFF supports a wide variety of models, including just about any model you can write in tf.keras
.
You can also create a TFF model directly by subclassing https://www.tensorflow.org/federated/api_docs/python/tff/learning/Model with the code for your forward pass. If you are interested in a more functional approach, you could also define an SVM model via TFF’s FunctionalModel https://www.tensorflow.org/federated/api_docs/python/tff/learning/models/FunctionalModel.
Answered By – Zachary Charles
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0