前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >标准TensorFlow格式 TFRecords

标准TensorFlow格式 TFRecords

作者头像
演化计算与人工智能
发布2020-08-14 10:52:22
6860
发布2020-08-14 10:52:22
举报

TFRecords可以允许你讲任意的数据转换为TensorFlow所支持的格式, 这种方法可以使TensorFlow的数据集更容易与网络应用架构相匹配。这种建议的方法就是使用TFRecords文件,TFRecords文件包含了[tf.train.Example 协议内存块(protocol buffer)](协议内存块包含了字段[Features]。你可以写一段代码获取你的数据, 将数据填入到Example协议内存块(protocol buffer),将协议内存块序列化为一个字符串, 并且通过[tf.python_io.TFRecordWriter class]写入到TFRecords文件。

TFRecords文件格式在图像识别中有很好的使用,其可以将二进制数据和标签数据(训练的类别标签)数据存储在同一个文件中,它可以在模型进行训练之前通过预处理步骤将图像转换为TFRecords格式,此格式最大的优点实践每幅输入图像和与之关联的标签放在同一个文件中.TFRecords文件是一种二进制文件,其不对数据进行压缩,所以可以被快速加载到内存中.格式不支持随机访问,因此它适合于大量的数据流,但不适用于快速分片或其他非连续存取。

TFRecordWriter

tf.python_io.TFRecordWriter.write(record)

Write a string record to the file. 将字符记录写到文件中,注意传入的参数是string类型的字符串.

Args:

record: str


TFRecordReader

class tf.TFRecordReader

A Reader that outputs the records from a TFRecords file. 从TFrecords文件中读取记录 See ReaderBase for supported methods.


tf.TFRecordReader.__init__(name=None)

Create a TFRecordReader. 创建一个TFRecordReader

  • name: A name for the operation (optional).

tf.TFRecordReader.num_records_produced(name=None)

Returns the number of records this reader has produced.

This is the same as the number of Read executions that have succeeded. 返回这个阅读器生成的记录的数量。这与已成功执行读取操作的数量相同。

  • name: A name for the operation (optional).

Returns:

An int64 Tensor. 一个int64位张量.


tf.TFRecordReader.num_work_units_completed(name=None)

Returns the number of work units this reader has finished processing. 返回该阅读器完成处理的工作单元的数量。

Args:

  • name: A name for the operation (optional).

Returns:

An int64 Tensor.


tf.TFRecordReader.read(queue, name=None)

Returns the next record (key, value pair) produced by a reader. 返回一个阅读器生成的下一个记录(键值对)。Will dequeue a work unit from queue if necessary (e.g. when the Reader needs to start reading from a new file since it has finished with the previous file). 如果有必要,将从队列中对一个工作单元进行排序(例如,当读者需要从一个新文件开始阅读时,因为它已经完成了前面的文件)。

Args:

  • queue: A Queue or a mutable string Tensor representing a handle to a Queue, with string work items. 文件名队列句柄
  • name: A name for the operation (optional).

Returns:

A tuple of Tensors (key, value).

  • key: A string scalar Tensor.
  • value: A string scalar Tensor. 返回键值对,其中值表示读取的文件

tf.TFRecordReader.reset(name=None)

Restore a reader to its initial clean state. 恢复一个文件阅读器使其置空

Args:

  • name: A name for the operation (optional).

Returns:

The created Operation.


tf.TFRecordReader.restore_state(state, name=None)

Restore a reader to a previously saved state. 恢复阅读器至先前保存的状态. Not all Readers support being restored, so this can produce an Unimplemented error. 并不是所有的阅读器都可以实现恢复的操作,所以这有可能导致一个未实现的错误.

Args:

  • state: A string Tensor. 一个字符串张量 Result of a SerializeState of a Reader with matching type. 一个具有匹配类型的阅读器的串行化的结果。
  • name: A name for the operation (optional).

Returns:

The created Operation.


tf.TFRecordReader.serialize_state(name=None)

Produce a string tensor that encodes the state of a reader. 产生一个字符串张量,它可以对一个阅读器的状态进行编码。

Not all Readers support being serialized, so this can produce an Unimplemented error. 不是所有的阅读器都支持编码,所以这会导致一个未实现的错误.

Args:

  • name: A name for the operation (optional).

Returns:

A string Tensor.


tf.TFRecordReader.supports_serialize

Whether the Reader implementation can serialize its state. 阅读器是否可以实现对当前状态进行编码.


本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DrawSky 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • TFRecordWriter
  • TFRecordReader
    • class tf.TFRecordReader
      • tf.TFRecordReader.__init__(name=None)
        • tf.TFRecordReader.num_records_produced(name=None)
          • Returns:
            • tf.TFRecordReader.num_work_units_completed(name=None)
              • Args:
                • Returns:
                  • tf.TFRecordReader.read(queue, name=None)
                    • Args:
                      • Returns:
                        • tf.TFRecordReader.reset(name=None)
                          • Args:
                            • Returns:
                              • tf.TFRecordReader.restore_state(state, name=None)
                                • Args:
                                  • Returns:
                                    • tf.TFRecordReader.serialize_state(name=None)
                                      • Args:
                                        • Returns:
                                          • tf.TFRecordReader.supports_serialize
                                          相关产品与服务
                                          数据保险箱
                                          数据保险箱(Cloud Data Coffer Service,CDCS)为您提供更高安全系数的企业核心数据存储服务。您可以通过自定义过期天数的方法删除数据,避免误删带来的损害,还可以将数据跨地域存储,防止一些不可抗因素导致的数据丢失。数据保险箱支持通过控制台、API 等多样化方式快速简单接入,实现海量数据的存储管理。您可以使用数据保险箱对文件数据进行上传、下载,最终实现数据的安全存储和提取。
                                          领券
                                          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档