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

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

我是机器学习的新手,正在尝试 Tensorflow (https://www.tensorflow.org/federated/tutorials/federated_learning_for_image_classification) 的“图像分类联合学习”代码。我 运行 Google Colab 上的代码并没有修改任何东西。

#@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

以上效果很好。 (没有错误) 但是当涉及到以下内容时:

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!')()

我在 import tensorflow_federated as tff 行遇到错误:

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

我已经搜索了类似 pip install -U TensorFlow-privacy 的解决方案,但 none 有效。

请帮忙。 提前致谢!

不是您问题的解决方案,但据我所知,除了 tff 优化器之外没有其他教程需要 tff 每晚,因此您可以只使用稳定的 tff 版本。

!pip install --quiet --upgrade tensorflow-federated
!pip install --quiet --upgrade nest-asyncio

import nest_asyncio
nest_asyncio.apply()

这个应该安装 tff 0.19