我正在try 将TensorFlow导入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,但此问题仍然存在

推荐答案

我遇到了同样的问题,并通过安装夜间版本进行了修复,

pip install tfds-nightly

它导入相同的内容,因此确保卸载常规的TensorFlow-DataSet.如果这不起作用,也许可以试着重建你的环境/venv/等等.

程序包版本:

Python: 3.9
tensorflow: 2.13.0
tfds-nightly: 4.9.3.dev202309250044

Python-3.x相关问答推荐

如何翻转以列形式给出的日期间隔并提取多个重叠时段内每小时的音量?

是否可以使用参数对Flask重定向?

正则表达式匹配并提取括号前的单词

如何转换Pandas中的数据,以使我 Select 的列名变为行值并增加行?

从.csv导入将文件夹路径加入到文件名

Pandas -我们如何在一行中应用多个要求

两个 y 轴在零处对齐的 plotly barplot

Django - ValueError:无法将字符串转换为浮点数:''

为什么 mypy 不适用于 sqlalchemy?

SqlAlchemy - 从 oracle db 中检索长文本

使用 Python 解析 JSON 嵌套字典

Python - 如何从同一台客户端机器运行多个Flask应用程序

你如何表达一个没有参数的 Python Callable?

有没有更好的方法来判断一个数字是否是两个数字的范围

Python - For 循环数百万行

PySpark python 问题:Py4JJavaError: An error occurred while calling o48.showString

从大字典中弹出 N 项的最快方法

try 在 Windows 10 高 DPI 显示器上解决模糊的 tkinter 文本 + zoom ,但担心我的方法不是 Pythonic 或不安全

Django Rest 框架 ListField 和 DictField

如何阻止散景在 Jupyter Notebook 中打开新标签?