tensorflowgoogle-colaboratoryattributeerrortensorflow-federatedfederated-learning

AttributeError: module 'tensorflow_privacy' has no attribute 'DPQuery'


I am new to machine learning and was trying out the "federated learning for image classification" code by Tensorflow (https://www.tensorflow.org/federated/tutorials/federated_learning_for_image_classification). I ran the code on Google Colab and did not modify anything.

#@test {"skip": true}

# tensorflow_federated_nightly also bring in tf_nightly, which
# can causes a duplicate tensorboard install, leading to errors.
!pip uninstall --yes tensorboard tb-nightly

!pip install --quiet --upgrade tensorflow-federated-nightly
!pip install --quiet --upgrade nest-asyncio
!pip install --quiet --upgrade tb-nightly  # or tensorboard, but not both

import nest_asyncio
nest_asyncio.apply()

%load_ext tensorboard

The above works well. (no errors) But when it comes to the below:

import collections

import numpy as np
import tensorflow as tf
import tensorflow_federated as tff

np.random.seed(0)

tff.federated_computation(lambda: 'Hello, World!')()

I got an error on the import tensorflow_federated as tff line:

AttributeError: module 'tensorflow_privacy' has no attribute 'DPQuery'

I've searched for solutions like pip install -U TensorFlow-privacy but none works.

Please help. Thanks in advance!


Solution

  • Not a solution to your problem but afaik no tutorial other than the tff optimizers require tff nightly, so you can just use stable tff releases.

    !pip install --quiet --upgrade tensorflow-federated
    !pip install --quiet --upgrade nest-asyncio
    
    import nest_asyncio
    nest_asyncio.apply()
    

    this one should install tff 0.19