Issue
I am trying to import tensorflow in jupyter notebook as in
import time
import keras_cv
from tensorflow import keras
import matplotlib.pyplot as plt
after restarting and having a fresh kernel and then running the block first error it shows is:
Using TensorFlow backend
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <cell line: 2>()
1 import time
----> 2 import keras_cv
3 from tensorflow import keras
4 import matplotlib.pyplot as plt
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\__init__.py:8, in <module>
1 """DO NOT EDIT.
2
3 This file was autogenerated. Do not edit it by hand,
4 since your modifications would be overwritten.
5 """
----> 8 from keras_cv import bounding_box
9 from keras_cv import callbacks
10 from keras_cv import core
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\bounding_box\__init__.py:8, in <module>
1 """DO NOT EDIT.
2
3 This file was autogenerated. Do not edit it by hand,
4 since your modifications would be overwritten.
5 """
----> 8 from keras_cv.src.bounding_box.converters import convert_format
9 from keras_cv.src.bounding_box.ensure_tensor import ensure_tensor
10 from keras_cv.src.bounding_box.formats import CENTER_XYWH
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\__init__.py:32, in <module>
30 from keras_cv.src import bounding_box
31 from keras_cv.src import callbacks
---> 32 from keras_cv.src import datasets
33 from keras_cv.src import layers
34 from keras_cv.src import losses
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\datasets\__init__.py:14, in <module>
1 # Copyright 2022 The KerasCV Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from keras_cv.src.datasets import pascal_voc
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\datasets\pascal_voc\__init__.py:14, in <module>
1 # Copyright 2022 The KerasCV Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from keras_cv.src.datasets.pascal_voc.load import load
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\datasets\pascal_voc\load.py:16, in <module>
1 # Copyright 2022 The KerasCV Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 import tensorflow as tf
---> 16 import tensorflow_datasets as tfds
18 from keras_cv.src import bounding_box
19 from keras_cv.src.api_export import keras_cv_export
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\__init__.py:43, in <module>
41 _TIMESTAMP_IMPORT_STARTS = time.time()
42 from absl import logging
---> 43 import tensorflow_datasets.core.logging as _tfds_logging
44 from tensorflow_datasets.core.logging import call_metadata as _call_metadata
46 _metadata = _call_metadata.CallMetadata()
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\__init__.py:22, in <module>
18 # Allow to use `tfds.core.Path` in dataset implementation which seems more
19 # natural than having to import a third party module.
20 from etils.epath import Path
---> 22 from tensorflow_datasets.core import community
23 from tensorflow_datasets.core.dataset_builder import BeamBasedBuilder
24 from tensorflow_datasets.core.dataset_builder import BuilderConfig
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\community\__init__.py:18, in <module>
1 # coding=utf-8
2 # Copyright 2023 The TensorFlow Datasets Authors.
3 #
(...)
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 """Community dataset API."""
---> 18 from tensorflow_datasets.core.community.huggingface_wrapper import mock_builtin_to_use_gfile
19 from tensorflow_datasets.core.community.huggingface_wrapper import mock_huggingface_import
20 from tensorflow_datasets.core.community.load import builder_cls_from_module
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\community\huggingface_wrapper.py:31, in <module>
28 from unittest import mock
30 from etils import epath
---> 31 from tensorflow_datasets.core import dataset_builder
32 from tensorflow_datasets.core import dataset_info
33 from tensorflow_datasets.core import download
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\dataset_builder.py:44, in <module>
42 from tensorflow_datasets.core import reader as reader_lib
43 from tensorflow_datasets.core import registered
---> 44 from tensorflow_datasets.core import split_builder as split_builder_lib
45 from tensorflow_datasets.core import splits as splits_lib
46 from tensorflow_datasets.core import tf_compat
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\split_builder.py:37, in <module>
35 from tensorflow_datasets.core import splits as splits_lib
36 from tensorflow_datasets.core import utils
---> 37 from tensorflow_datasets.core import writer as writer_lib
38 from tensorflow_datasets.core.utils import shard_utils
40 if typing.TYPE_CHECKING:
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\writer.py:33, in <module>
31 from tensorflow_datasets.core import lazy_imports_lib
32 from tensorflow_datasets.core import naming
---> 33 from tensorflow_datasets.core import shuffle
34 from tensorflow_datasets.core import utils
35 from tensorflow_datasets.core.utils import file_utils
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\core\shuffle.py:20, in <module>
18 import math
19 import os
---> 20 import resource
21 import struct
22 from typing import Iterator, List, Optional
ModuleNotFoundError: No module named 'resource'
With the same kernel, if I run the block again (using CTRL+ENTER) it shows:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Input In [2], in <cell line: 2>()
1 import time
----> 2 import keras_cv
3 from tensorflow import keras
4 import matplotlib.pyplot as plt
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\__init__.py:11, in <module>
9 from keras_cv import callbacks
10 from keras_cv import core
---> 11 from keras_cv import datasets
12 from keras_cv import keypoint
13 from keras_cv import layers
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\datasets\__init__.py:8, in <module>
1 """DO NOT EDIT.
2
3 This file was autogenerated. Do not edit it by hand,
4 since your modifications would be overwritten.
5 """
----> 8 from keras_cv.datasets import imagenet
9 from keras_cv.datasets import pascal_voc
10 from keras_cv.datasets import waymo
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\datasets\imagenet\__init__.py:8, in <module>
1 """DO NOT EDIT.
2
3 This file was autogenerated. Do not edit it by hand,
4 since your modifications would be overwritten.
5 """
----> 8 from keras_cv.src.datasets.imagenet.load import load
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\__init__.py:32, in <module>
30 from keras_cv.src import bounding_box
31 from keras_cv.src import callbacks
---> 32 from keras_cv.src import datasets
33 from keras_cv.src import layers
34 from keras_cv.src import losses
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\datasets\__init__.py:14, in <module>
1 # Copyright 2022 The KerasCV Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from keras_cv.src.datasets import pascal_voc
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\datasets\pascal_voc\__init__.py:14, in <module>
1 # Copyright 2022 The KerasCV Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from keras_cv.src.datasets.pascal_voc.load import load
File ~\AppData\Roaming\Python\Python310\site-packages\keras_cv\src\datasets\pascal_voc\load.py:16, in <module>
1 # Copyright 2022 The KerasCV Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
(...)
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 import tensorflow as tf
---> 16 import tensorflow_datasets as tfds
18 from keras_cv.src import bounding_box
19 from keras_cv.src.api_export import keras_cv_export
File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\__init__.py:43, in <module>
41 _TIMESTAMP_IMPORT_STARTS = time.time()
42 from absl import logging
---> 43 import tensorflow_datasets.core.logging as _tfds_logging
44 from tensorflow_datasets.core.logging import call_metadata as _call_metadata
46 _metadata = _call_metadata.CallMetadata()
ImportError: cannot import name 'core' from partially initialized module 'tensorflow_datasets' (most likely due to a circular import) (C:\Users\ROHIT\AppData\Roaming\Python\Python310\site-packages\tensorflow_datasets\__init__.py)
I have resource and tensorflow already installed through pip but this issue still persists
Solution
I was running into the same issue and it was fixed by installing the nightly build,
pip install tfds-nightly
It imports the same, so make sure to uninstall the regular tensorflow-datasets. If that doesn't work, maybe try to rebuild your environment/venv/etc.
Package Versions:
Python: 3.9
tensorflow: 2.13.0
tfds-nightly: 4.9.3.dev202309250044
Answered By - Ronen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.