AttributeError:模块“tensorflow.io”没有属性“experimental”

4 python python-3.x tensorflow tensorflow2.0

我试图从tensorflow调用一个函数来解码tiff图像,同时我在kaggle笔记本上运行笔记本并在这一行中:

img = tfio.experimental.image.decode_tiff(img, channels=1)
Run Code Online (Sandbox Code Playgroud)

它给了我错误:

属性错误:在用户代码中:

<ipython-input-5-d30698f56813>:11 load  *
    img = tfio.experimental.image.decode_tiff(img, channels=1)

AttributeError: module 'tensorflow.io' has no attribute 'experimental'
Run Code Online (Sandbox Code Playgroud)

我目前正在像这样导入tensorflow.io:

import tensorflow.io as tfio
Run Code Online (Sandbox Code Playgroud)

我当前的版本print(f"Tensorflow ver. {tf.__version__}")是:

张量流版本。2.3.0

des*_*aut 5

Tensorflow I/O 不随 Tensorflow 一起提供,必须通过 单独安装pip;来自回购协议(强调我的):

TensorFlow I/O 是TensorFlow 内置支持中提供的文件系统和文件格式的集合。

而且,它不是那样进口的。

你应该做的是通过以下方式安装它pip

!pip install tensorflow-io
Run Code Online (Sandbox Code Playgroud)

并验证您是否获得了最新版本 v0.15.0,因为它是目前唯一与 TF 2.3 兼容的版本(来源):

import tensorflow_io as tfio
tfio.__version__
# 0.15.0
Run Code Online (Sandbox Code Playgroud)

注意不同的导入 - tensorflow_io,而不是 tensorflow.io; Github中的简单使用示例也演示了这一点。