跳转到主要内容

TensorFlow I/O

项目描述




TensorFlow I/O

GitHub CI PyPI License Documentation

TensorFlow I/O 是一组文件系统和文件格式,这些系统在 TensorFlow 的内置支持中不可用。TensorFlow I/O 支持的文件系统和文件格式的完整列表可以在这里找到。

使用 tensorflow-io 与 keras 一起使用非常简单。以下是一个示例,用 tensorflow-io 替换了数据处理的方面,以开始使用 TensorFlow

import tensorflow as tf
import tensorflow_io as tfio

# Read the MNIST data into the IODataset.
dataset_url = "https://storage.googleapis.com/cvdf-datasets/mnist/"
d_train = tfio.IODataset.from_mnist(
    dataset_url + "train-images-idx3-ubyte.gz",
    dataset_url + "train-labels-idx1-ubyte.gz",
)

# Shuffle the elements of the dataset.
d_train = d_train.shuffle(buffer_size=1024)

# By default image data is uint8, so convert to float32 using map().
d_train = d_train.map(lambda x, y: (tf.image.convert_image_dtype(x, tf.float32), y))

# prepare batches the data just like any other tf.data.Dataset
d_train = d_train.batch(32)

# Build the model.
model = tf.keras.models.Sequential(
    [
        tf.keras.layers.Flatten(input_shape=(28, 28)),
        tf.keras.layers.Dense(512, activation=tf.nn.relu),
        tf.keras.layers.Dropout(0.2),
        tf.keras.layers.Dense(10, activation=tf.nn.softmax),
    ]
)

# Compile the model.
model.compile(
    optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]
)

# Fit the model.
model.fit(d_train, epochs=5, steps_per_epoch=200)

在上面的 MNIST 示例中,访问数据集文件的 URL 直接传递给 tfio.IODataset.from_mnist API 调用。这是由于 tensorflow-ioHTTP/HTTPS 文件系统的固有支持,从而消除了在本地目录中下载和保存数据集的需求。

注意:由于 tensorflow-io 能够在需要时自动检测和解压缩 MNIST 数据集,因此我们可以直接将压缩文件(gzip)的 URL 传递给 API 调用。

请查看官方文档以获取更多详细和有趣的包用法。

安装

Python 包

可以使用以下命令直接使用 pip 安装 tensorflow-io Python 包:

$ pip install tensorflow-io

稍微有些冒险的人也可以尝试我们的夜间二进制文件

$ pip install tensorflow-io-nightly

为了确保您拥有与 TensorFlow-IO 兼容的 TensorFlow 版本,您可以在安装期间指定 tensorflow 额外需求

pip install tensorflow-io[tensorflow]

类似的外部程序存在于 tensorflow-gputensorflow-cputensorflow-rocm 包中。

Docker 镜像

除了 pip 包之外,还可以使用 docker 镜像快速开始。

对于稳定构建

$ docker pull tfsigio/tfio:latest
$ docker run -it --rm --name tfio-latest tfsigio/tfio:latest

对于夜间构建

$ docker pull tfsigio/tfio:nightly
$ docker run -it --rm --name tfio-nightly tfsigio/tfio:nightly

R 包

成功安装 tensorflow-io Python 包后,您可以通过以下方式从 GitHub 安装 R 包的开发版本:

if (!require("remotes")) install.packages("remotes")
remotes::install_github("tensorflow/io", subdir = "R-package")

TensorFlow 版本兼容性

为确保与 TensorFlow 兼容,建议根据以下表格安装匹配版本的 TensorFlow I/O。您可以在这里找到版本列表。

TensorFlow I/O 版本 TensorFlow 兼容性 发布日期
0.31.0 2.11.x 2022 年 2 月 25 日
0.30.0 2.11.x 2022 年 1 月 20 日
0.29.0 2.11.x 2022 年 12 月 18 日
0.28.0 2.11.x 2022 年 11 月 21 日
0.27.0 2.10.x 2022 年 9 月 8 日
0.26.0 2.9.x 2022 年 5 月 17 日
0.25.0 2.8.x 2022 年 4 月 19 日
0.24.0 2.8.x 2022 年 2 月 4 日
0.23.1 2.7.x 2021 年 12 月 15 日
0.23.0 2.7.x 2021 年 12 月 14 日
0.22.0 2.7.x 2021 年 11 月 10 日
0.21.0 2.6.x 2021 年 9 月 12 日
0.20.0 2.6.x 2021 年 8 月 11 日
0.19.1 2.5.x 2021 年 7 月 25 日
0.19.0 2.5.x 2021 年 6 月 25 日
0.18.0 2.5.x 2021 年 5 月 13 日
0.17.1 2.4.x 2021 年 4 月 16 日
0.17.0 2.4.x 2020 年 12 月 14 日
0.16.0 2.3.x 2020 年 10 月 23 日
0.15.0 2.3.x 2020 年 8 月 3 日
0.14.0 2.2.x 2020 年 7 月 8 日
0.13.0 2.2.x 2020 年 5 月 10 日
0.12.0 2.1.x 2020 年 2 月 28 日
0.11.0 2.1.x 2020 年 1 月 10 日
0.10.0 2.0.x 2019 年 12 月 5 日
0.9.1 2.0.x 2019 年 11 月 15 日
0.9.0 2.0.x 2019 年 10 月 18 日
0.8.1 1.15.x 2019 年 11 月 15 日
0.8.0 1.15.x 2019 年 10 月 17 日
0.7.2 1.14.x 2019 年 11 月 15 日
0.7.1 1.14.x 2019 年 10 月 18 日
0.7.0 1.14.x 2019 年 7 月 14 日
0.6.0 1.13.x 2019 年 5 月 29 日
0.5.0 1.13.x 2019 年 4 月 12 日
0.4.0 1.13.x 2019 年 3 月 1 日
0.3.0 1.12.0 2019 年 2 月 15 日
0.2.0 1.12.0 2019 年 1 月 29 日
0.1.0 1.12.0 2018 年 12 月 16 日

性能基准测试

我们使用 github-pages 来记录 API 性能基准测试的结果。基准测试作业在每次向 master 分支提交时触发,并有助于跟踪与提交相关的性能。

贡献

Tensorflow I/O 是一个由社区领导的开源项目。因此,该项目依赖于公共贡献、错误修复和文档。请参阅

构建状态和持续集成

构建 状态
Linux CPU Python 2 Status
Linux CPU Python 3 Status
Linux GPU Python 2 Status
Linux GPU Python 3 Status

由于许多linux2010的要求,TensorFlow I/O在Linux上使用Ubuntu:16.04 + Developer Toolset 7 (GCC 7.3)构建。在Ubuntu 16.04上使用Developer Toolset 7进行配置并不完全直接。如果系统已安装Docker,则以下命令将自动构建许多linux2010兼容的whl软件包。

#!/usr/bin/env bash

ls dist/*
for f in dist/*.whl; do
  docker run -i --rm -v $PWD:/v -w /v --net=host quay.io/pypa/manylinux2010_x86_64 bash -x -e /v/tools/build/auditwheel repair --plat manylinux2010_x86_64 $f
done
sudo chown -R $(id -nu):$(id -ng) .
ls wheelhouse/*

构建需要一些时间,但一旦完成,就会在wheelhouse目录中提供python 3.53.63.7兼容的whl软件包。

在macOS上,可以使用相同的命令。然而,脚本期望在shell中使用python,并且只会生成与shell中python版本匹配的whl软件包。如果您想为特定的python构建whl软件包,则必须在shell中将此版本的python别名为python。有关如何操作的说明,请参阅.github/workflows/build.yml中的Auditwheel步骤。

注意,上述命令也是我们用于发布Linux和macOS软件包的命令。

TensorFlow I/O使用GitHub Workflows和Google CI (Kokoro)进行持续集成。GitHub Workflows用于macOS构建和测试。Kokoro用于Linux构建和测试。再次强调,由于许多linux2010的要求,在Linux上构建的whl软件包总是使用Ubuntu 16.04 + Developer Toolset 7。测试在各种具有不同python3版本的系统上进行,以确保良好的覆盖率。

Python Ubuntu 18.04 Ubuntu 20.04 macOS + osx9 Windows-2019
2.7 :heavy_check_mark :heavy_check_mark :heavy_check_mark N/A
3.7 :heavy_check_mark :heavy_check_mark :heavy_check_mark :heavy_check_mark
3.8 :heavy_check_mark :heavy_check_mark :heavy_check_mark :heavy_check_mark

TensorFlow I/O与许多系统和云提供商(如Prometheus、Apache Kafka、Apache Ignite、Google Cloud PubSub、AWS Kinesis、Microsoft Azure Storage、Alibaba Cloud OSS等)集成。

我们尽最大努力在我们的持续集成中测试这些系统。某些测试(如Prometheus、Kafka和Ignite)是在实时系统上进行的,这意味着我们在测试运行之前在CI机器上安装了Prometheus/Kafka/Ignite。某些测试(如Kinesis、PubSub和Azure Storage)是通过官方或非官方的模拟器进行的。只要可能,也会进行离线测试,尽管通过离线测试覆盖的系统可能没有实时系统或模拟器那样的覆盖率。

实时系统 模拟器 CI集成 离线
Apache Kafka :heavy_check_mark :heavy_check_mark
Apache Ignite :heavy_check_mark :heavy_check_mark
Prometheus :heavy_check_mark :heavy_check_mark
Google PubSub :heavy_check_mark :heavy_check_mark
Azure Storage :heavy_check_mark :heavy_check_mark
AWS Kinesis :heavy_check_mark :heavy_check_mark
Alibaba Cloud OSS :heavy_check_mark
Google BigTable/BigQuery 待添加
Elasticsearch (实验性) :heavy_check_mark :heavy_check_mark
MongoDB (实验性) :heavy_check_mark :heavy_check_mark

模拟器的参考资料

社区

其他信息

许可证

Apache License 2.0

项目详情


发布历史 发布通知 | RSS 源

下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

此版本没有可用的源代码分发文件。请参阅生成分发归档教程

构建分发

支持者包括: