【问题标题】:import tensorflow_federated as tff error in google colab将 tensorflow_federated 导入为 google colab 中的 tff 错误
【发布时间】:2022-12-22 12:38:03
【问题描述】:

您好,我正在使用 google colab,我在将 tensorflow_federated 导入为 tff 时遇到问题,它之前运行良好,我不知道现在是什么问题。

这是我的代码: 我安装了所有的 nessacery pip 库,一切都在 tff 的 0.20.0 版中运行良好。我也尝试安装最新版本 0.33.0,但它不起作用任何人都可以帮助我,请问出了什么问题???

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

import nest_asyncio
nest_asyncio.apply()
%load_ext tensorboard
!pip install h5py
!pip install typing-extensions
!pip install wheel
!pip install tensorflow
!pip install --quiet tensorflow-federated==0.20.0

这是我的进口商品:

import pandas as pd 
import collections 
import numpy as np
np.random.seed(0)
import tensorflow as tf
from tensorflow.python.keras.optimizer_v2 import gradient_descent
import tensorflow_federated as tff
from random import choices
import matplotlib.pyplot as plt
from google.colab import drive 
import functools
from absl import app
from absl import flags
from absl import logging
import abc
from typing import Any, Callable, Iterable, List, Optional, Sequence, Tuple, Union
from tensorflow_federated.python.common_libs import py_typecheck

这是我尝试导入 tff 时的错误:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-17-bcd46adc5a91> in <module>
      5 import tensorflow as tf
      6 from tensorflow.python.keras.optimizer_v2 import gradient_descent
----> 7 import tensorflow_federated as tff
      8 from random import choices
      9 import matplotlib.pyplot as plt

/usr/local/lib/python3.7/dist-packages/tensorflow_federated/__init__.py in <module>
     79 # the directory structure. The python import statements above implicitly add
     80 # these to locals().
---> 81 del python  # pylint:disable=undefined-variable
     82 del proto  # pylint:disable=undefined-variable

NameError: name 'python' is not defined

当我尝试第一个 pip 时也出现错误:

错误:pip 的依赖项解析器当前没有考虑所有已安装的包。此行为是以下依赖项冲突的根源。 pymc 4.1.4 需要 cachetools>=4.2.1,但您有不兼容的 cachetools 3.1.1。 grpcio-status 1.48.2 要求 grpcio>=1.48.2,但是您有不兼容的 grpcio 1.46.5。 google-colab 1.0.0 需要 portpicker~=1.3.1,但您有不兼容的 portpicker 1.5.2。 google-cloud-bigquery 3.3.6 需要 grpcio<2.0dev,>=1.47.0,但您有不兼容的 grpcio 1.46.5。

【问题讨论】:

  • 嗨 @ASh,你能告诉我们你在 colab 中使用的是哪个版本的 tensorflow 吗?谢谢你。

标签: python tensorflow google-colaboratory tensorflow-federated


【解决方案1】:

如此处的文档所述 Tff tutorials

据说 tff 需要 Python 3.9,而 Google Colab 当前版本在 Python 3.8.16 上运行

Colab python version

您可以尝试在本地计算机上运行它,或者将 python colab 版本升级到 3.9 --here's how to upgrade

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-16
    • 2023-02-14
    • 2020-11-28
    • 2021-03-30
    • 2022-08-20
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多