我想在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笔记本并将内核更改为py3-TF2.0时(请注意,我只能在ANACONDA NAVIGATOR中更改内核,而在Jupyter笔记本环境中则不能更改)。在该内核中打开脚本,然后按“重新启动内核并运行所有脚本”,我收到错误消息。
我尝试再次安装内核;没有错误消息(删除原始内核并替换它似乎不是问题)。
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上发现了一个非常类似的情况:Not able to import tensorflow_datasets module in jupyter notebook,但错误消息似乎与我的完全不同。
答案 0 :(得分:3)
旧的pip install tensorflow-datasets不能与在conda环境中安装tensorflow-datasets一起使用 使用下面的代码使其与tensorflow 2.1.0一起使用
conda install -c anaconda tensorflow-datasets
答案 1 :(得分:1)
由于旧的tensorflow版本与旧的tensorflow数据集的组合而发生此问题。
所以首先要升级您的张量流版本:
!pip install tensorflow-gpu==2.1.0
然后使用张量流数据集。
!pip install -U tensorflow_datasets
答案 2 :(得分:0)
我找到了答案;问题出在Tensorflow2.0.0-alpha0 这是使用Tensorflow2.0.0的beta版本修补的