Tensorflow Dataset API详解

Tensorflow是一个十分受欢迎的深度学习框架。为了提高框架的性能和易使用性,随着版本的迭代,tensorflow逐步添加了许多高级API。这些高级API中,有一部分是对原来API的更高级封装,还有一部分就是为了提高性能(取代旧API)而开发出来的新API。其中,Dataset API和Estimator APITensorFlow 1.3 中引入的高级API,官方文档也推荐用户使用它们创建模型。

  • Datasets一种为 TensorFlow 模型创建输入管道的新方式。The Dataset API has methods to load and manipulatedata,and feed it into your model. The Datasets API meshes well with the Estimators API.
  • Estimators:用来表示一个完整的 TensorFlow 模型。The Estimator API provides methods to train the model, to judgethe model's accuracy, and to generate predictions.

下图是tensorflow API的完整架构图:


在TensorFlow 1.3以前的版本中总体来说有两种读取数据方法:

Dataset API是从 TensorFlow 1.3开始添加新的输入管道。使用此 API 的性能要比使用 feed_dict 或队列式管道的性能高得多,而且此 API 更简洁,使用起来更容易。在TensorFlow 1.3中,Dataset API是放在contrib包中的:tf.contrib.data.Dataset,而在TensorFlow 1.4中则是tf.data.Dataset。

 Datasets API是由以下图中所示的类组成:


其中:

  • Dataset: Base class containing methods tocreate and transform datasets. Also allows you to initialize a dataset from data in memory, or from a Python generator.
  • TextLineDataset: Reads lines from text files(txt,csv...).
  • TFRecordDataset: Reads records from TFRecord files.
  • FixedLengthRecordDataset: Reads fixed size records from binary files.
  • Iterator: Provides a way to access one data set element at a time.
总之, Datasets API实现了从内存或者硬盘文件中加载数据组成数据集,同时对数据集进行一系列变换操作,最终将数据集提供给其他API使用的一系列功能。下面,本文就将从这三个方面对Datasets API进行介绍。


1. 加载数据形成数据集

 (1)从内存或迭代器中加载数据:

 A single element of a Dataset contains one or more tf.Tensor objects, called components.Which may be a single tensor,

a tuple of tensors, or a nested tuple of tensors. And in addition to tuples, you

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值