导入 tensorflow_datasets 时出现错误 [英] I get an error when importing tensorflow_datasets
问题描述
我想在 Jupyter(版本 6.0.0)中使用 Python3 tensorflow_datasets.这样做会导致出现错误消息,我似乎无法理解问题是什么.
I want to use in Jupyter (version 6.0.0) with Python3 tensorflow_datasets. Doing that results in an error message I cannot seem to fathom what the problem is.
我为 Python 制作了一个新内核,它应该使用 tensorflow_datasets.采取了以下步骤(在 anaconda 中使用我的管理员选项).
I made a new kernel for Python which should utilize the tensorflow_datasets. The following steps were taken (In anaconda using my administrator option).
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
关闭后我重新启动了我的笔记本电脑.
Upon closing I restarted my laptop.
当我打开 Jupyter notebook 并将内核更改为 py3-TF2.0 时(请注意,我只能在 ANACONDA NAVIGATOR 中更改内核,而不能在 Jupyter notebook 环境中更改).打开该内核中的脚本,然后按重新启动内核并运行所有脚本",我收到错误消息.
When I open Jupyter notebook, and change my kernel to py3-TF2.0 (Do note that I only can change my kernel in the ANACONDA NAVIGATOR and NOT in Jupyter notebook enviroment). Open the script within that kernel and press 'restart kernel and run all scripts' I get the error message.
我再次尝试安装内核;它没有错误消息(删除原始内核并替换它似乎不是问题).
I retried installing the kernel again; which has no error messages (Removing the original kernel and replacing it doesnt seem to be a problem).
import numpy as np
import tensorflow as tf
import tensorflow_datasets as tfds
我希望没有错误信息;从而在 Jupyter 中正确导入了我的 tensorflow_datasets.
I expect no error message; and thus imported my tensorflow_datasets properly in Jupyter.
我得到的错误信息如下
---------------------------------------------------------------------------
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 模块,但错误消息似乎与我的完全不同.
I have searched on Stackoverflow, google and youtube on this matter. So far I found a rather similar case on stackoverflow : Not able to import tensorflow_datasets module in jupyter notebook but the error message seem to be entirely different from mine.
推荐答案
我找到了答案;问题在于 Tensorflow2.0.0-alpha0这是用 Tensorflow2.0.0 的测试版修补的
I have found the answer; the problem lies within Tensorflow2.0.0-alpha0 This is patched with the beta version of Tensorflow2.0.0
这篇关于导入 tensorflow_datasets 时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!