4

我想在 Jupyter(6.0.0 版)中使用 Python3 tensorflow_datasets。这样做会导致出现错误消息,我似乎无法理解问题所在。

我为 Python 制作了一个新内核,它应该利用 tensorflow_datasets。采取了以下步骤(在 anaconda 中使用我的管理员选项)。

1. conda info --envs
2. conda create --name py3-TF2.0 python=3
3. conda activate py3-TF2.0
4. pip install matplotlib
5. pip install tensorflow==2.0.0-alpha0
6. pip install ipykernel
7. conda install nb_conda_kernels
8. pip install tensorflow-datasets

关闭后,我重新启动了笔记本电脑。

当我打开 Jupyter notebook 并将我的内核更改为 py3-TF2.0 时(请注意,我只能在 ANACONDA NAVIGATOR 中更改我的内核,而不是在 Jupyter notebook 环境中)。打开该内核中的脚本并按“重新启动内核并运行所有脚本”我收到错误消息。

我再次尝试安装内核;没有错误消息(删除原始内核并替换它似乎不是问题)。

import numpy as np
import tensorflow as tf
import tensorflow_datasets as tfds

我希望没有错误消息;从而在 Jupyter 中正确导入了我的 tensorflow_datasets。

我得到的错误信息如下

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call 
last)
<ipython-input-1-3e405850b628> in <module>
  1 import numpy as np
  2 import tensorflow as tf
----> 3 import tensorflow_datasets as tfds
      4 
      5 # TensorFLow includes a data provider for MNIST that we'll use.

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site- 
   packages\tensorflow_datasets\__init__.py in <module>
     44 # needs to happen before anything else, since the imports below will try to
     45 # import tensorflow, too.
---> 46 from tensorflow_datasets.core import tf_compat
     47 tf_compat.ensure_tf_install()
     48 

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\__init__.py in <module>
 26 from tensorflow_datasets.core.dataset_builder import GeneratorBasedBuilder
 27 
---> 28 from tensorflow_datasets.core.dataset_info import DatasetInfo
     29 from tensorflow_datasets.core.dataset_info import Metadata
     30 from tensorflow_datasets.core.dataset_info import MetadataDict

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\dataset_info.py in <module>
     51 from tensorflow_datasets.core import splits as splits_lib
     52 from tensorflow_datasets.core import utils
---> 53 from tensorflow_datasets.core.features import top_level_feature
     54 from tensorflow_datasets.core.proto import dataset_info_pb2
     55 from tensorflow_datasets.core.proto import json_format

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\features\__init__.py in <module>
     25 from tensorflow_datasets.core.features.feature import Tensor
     26 from tensorflow_datasets.core.features.feature import TensorInfo
---> 27 from tensorflow_datasets.core.features.features_dict import FeaturesDict
     28 from tensorflow_datasets.core.features.image_feature import Image
     29 from tensorflow_datasets.core.features.sequence_feature import Sequence

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\features\features_dict.py in <module>
     26 from tensorflow_datasets.core import utils
     27 from tensorflow_datasets.core.features import feature as feature_lib
---> 28 from tensorflow_datasets.core.features import top_level_feature
     29 
     30 

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\features\top_level_feature.py in <module>
     25 
     26 
---> 27 class TopLevelFeature(feature_lib.FeatureConnector):
     28   """Top-level `FeatureConnector` to manage decoding.
     29 

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\py3-TF2.0\lib\site-packages\tensorflow_datasets\core\features\top_level_feature.py in TopLevelFeature()
     43   # disable it in methods that use them, to avoid the warning.
     44   # TODO(mdan): Remove decorator once AutoGraph supports mangled names.
---> 45   @tf.autograph.experimental.do_not_convert()
     46   def _set_top_level(self):
     47     """Indicates that the feature is top level.

AttributeError: module 'tensorflow._api.v2.autograph.experimental' has no attribute 'do_not_convert'

我已经在 Stackoverflow、google 和 youtube 上搜索过这个问题。到目前为止,我在 stackoverflow 上发现了一个相当相似的案例:无法在 jupyter notebook 中导入 tensorflow_datasets 模块,但错误消息似乎与我的完全不同。

4

3 回答 3

4

我找到了答案;问题出在 Tensorflow2.0.0-alpha0 这是用 Tensorflow2.0.0 的 beta 版本修补的

于 2019-07-25T13:34:14.347 回答
3

旧的 pip install tensorflow-datasets 不适用于在 conda 环境中安装 tensorflow-datasets 使用以下代码使其适用于 tensorflow 2.1.0

conda install -c anaconda tensorflow-datasets
于 2020-03-03T05:04:53.570 回答
1

由于旧 tensorflow 版本与旧 tensorflow 数据集的组合,会出现此问题。

所以首先升级你的 tensorflow 版本:

!pip install tensorflow-gpu==2.1.0

然后使用张量流数据集。

!pip install -U tensorflow_datasets

于 2020-03-09T05:35:28.240 回答