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 版)
372
13
如果你对 CSV 文件(或使用的任何其他格式)感到满意,就不必使用 TFRecords
俗话说,如果没有破裂,就不要修理!当训练过程中的瓶颈是加载和解析数
据时,TFRecords 很有用。
13.2 TFRecord 格式
TFRecord 格式是 TensorFlow 首选的格式,用于存储大量数据并有效读取数据。这是一
种非常简单的二进制格式,只包含大小不同的二进制记录序列(每个记录由一个长度、
一个用于检查长度是否损坏的 CRC 校验和、实际数据以及最后一个 CRC 校验和组成)。
你可以使用 tf.io.TFRecordWriter 类轻松创建 TFRecord 文件:
with
tf.io.TFRecordWriter("my_data.tfrecord")
as
f:
f.write(b"This is the first record")
f.write(b"And this is the second record")
然后你可以使用 tf.data.TFRecordDataset 读取一个或多个 TFRecord 文件:
filepaths = ["my_data.tfrecord"]
dataset = tf.data.TFRecordDataset(filepaths)
for
item in dataset:
print
(item)
这将输出:
tf.Tensor(b'This is the first record', shape=(), dtype=string) ...
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