Skip to Content
机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)
book

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

by Aurélien Géron
October 2020
Intermediate to advanced
693 pages
16h 26m
Chinese
China Machine Press
Content preview from 机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)
使用
TensorFlow
加载和预处理数据
363
TF
数据集
TFDS
提供方便的函数来下载各种类型的常见数据集,包括像 ImageNet 这样的大型数据
集与方便的数据集对象(可以使用 Data API 对其进行操作)。
因此,让我们开始吧!
13.1 数据 API
整个数据 API 都围绕着数据集的概念:你可能会怀疑,这代表了数据元素的一个序
列。通常,你使用的是逐步从磁盘中读取数据的数据集,但为了简单起见,让我们使用
tf.data.Dataset.from_tensor_slices() RAM 中完全创建一个数据集:
>>>
X = tf.range(10) #
any data tensor
>>>
dataset = tf.data.Dataset.from_tensor_slices(X)
>>>
dataset
<TensorSliceDataset shapes: (), types: tf.int32>
from_tensor_slices() 函数采用一个张量并创建一个 tf.data.Dataset,其元
素都是 X 的切片(沿第一个维度),因此此数据集包含 10 个元素:张量 012,…,9
在这种情况下,如果我们使用 tf.data.Dataset.range(10),则将获得相同的数
据集。
你可以像以下这样简单地遍历数据集的元素:
>>>
for
item
in
dataset:
...
print
(item)
...
tf.Tensor(0, shape=(), dtype=int32) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow
Go语言编程

Go语言编程

威廉·肯尼迪
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey

Publisher Resources

ISBN: 9787111665977