AttributeError: module 'tensorflow_federated.python.learning' has no attribute 'algorithms'
Question:
I am trying to run the code given by Tensorflow in their official documentation, pertaining to Tensorflow-Federated.
The code is as follows:
import tensorflow as tf
import tensorflow_federated as tff
def model_fn():
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(10, tf.nn.softmax, input_shape=(784,),
kernel_initializer='zeros')
])
trainer = tff.learning.algorithms.build_weighted_fed_avg(
model_fn,
client_optimizer_fn=lambda: tf.keras.optimizers.SGD(0.1))
However, I am getting the following error:
Traceback (most recent call last):
File "G:/pythonproject2/main.py", line 43, in <module>
trainer = tff.learning.algorithms.build_weighted_fed_avg(
AttributeError: module 'tensorflow_federated.python.learning' has no attribute 'algorithms'
Could someone please help me out?
Answers:
I found the issue, tensorflow_federated
requires Python 3.9+. Since I was using Python 3.7, I encountered the above error.
From the Tensorflow-Federated Documentation:
I encountered this issue described above so what you have to do:
1- upgrade your python version (3.9+) by using for example this line of code conda install python=3.9.2
if you use virtual env in anaconda
2- upgrade your pip, setuptools, wheel pip install --upgrade pip setuptools wheel
3- upgrade your tensorflow-federated by using pip install --upgrade tensorflow-federated
I solved this problem like this.
I am trying to run the code given by Tensorflow in their official documentation, pertaining to Tensorflow-Federated.
The code is as follows:
import tensorflow as tf
import tensorflow_federated as tff
def model_fn():
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(10, tf.nn.softmax, input_shape=(784,),
kernel_initializer='zeros')
])
trainer = tff.learning.algorithms.build_weighted_fed_avg(
model_fn,
client_optimizer_fn=lambda: tf.keras.optimizers.SGD(0.1))
However, I am getting the following error:
Traceback (most recent call last):
File "G:/pythonproject2/main.py", line 43, in <module>
trainer = tff.learning.algorithms.build_weighted_fed_avg(
AttributeError: module 'tensorflow_federated.python.learning' has no attribute 'algorithms'
Could someone please help me out?
I found the issue, tensorflow_federated
requires Python 3.9+. Since I was using Python 3.7, I encountered the above error.
From the Tensorflow-Federated Documentation:
I encountered this issue described above so what you have to do:
1- upgrade your python version (3.9+) by using for example this line of code conda install python=3.9.2
if you use virtual env in anaconda
2- upgrade your pip, setuptools, wheel pip install --upgrade pip setuptools wheel
3- upgrade your tensorflow-federated by using pip install --upgrade tensorflow-federated
I solved this problem like this.