Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get an error when importing 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.

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.

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

I expect no error message; and thus imported my tensorflow_datasets properly in Jupyter.

The error message I get is the following

---------------------------------------------------------------------------
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'

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.

like image 213
Ignavus Avatar asked Jan 26 '23 01:01

Ignavus


2 Answers

I have found the answer; the problem lies within Tensorflow2.0.0-alpha0 This is patched with the beta version of Tensorflow2.0.0

like image 160
Ignavus Avatar answered Jan 28 '23 16:01

Ignavus


the old pip install tensorflow-datasets wont work with installation of tensorflow-datasets inside conda environment use the below code to make it work with tensorflow 2.1.0

conda install -c anaconda tensorflow-datasets
like image 27
Abdul Rahim Abdul Rasheed Avatar answered Jan 28 '23 14:01

Abdul Rahim Abdul Rasheed