无法从部分初始化的模块“tensorflow_datasets”导入名称“core”(很可能是由于循环导入)

问题描述 投票:0回答:1

我正在尝试在 jupyter 笔记本中导入张量流,如下所示

import time
import keras_cv
from tensorflow import keras
import matplotlib.pyplot as plt

重新启动并拥有新内核后,然后运行块第一个错误,它显示的是:

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'

使用相同的内核,如果我再次运行该块(使用 CTRL+ENTER),它会显示:

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

我已经通过pip安装了资源和tensorflow,但这个问题仍然存在

python-3.x tensorflow jupyter-notebook python-import jupyter-lab
1个回答
0
投票

我遇到了同样的问题,通过安装夜间构建解决了这个问题,

pip install tfds-nightly

它导入相同的内容,因此请确保卸载常规的张量流数据集。如果这不起作用,也许尝试重建您的环境/venv/等。

套餐版本:

Python: 3.9
tensorflow: 2.13.0
tfds-nightly: 4.9.3.dev202309250044
© www.soinside.com 2019 - 2024. All rights reserved.