TFRecord文件查看包含的所有Features代码-创新互联

TFRecord作为tensorflow中广泛使用的数据格式,它跨平台,省空间,效率高。因为 Tensorflow开发者众多,统一训练时数据的文件格式是一件很有意义的事情,也有助于降低学习成本和迁移成本。

创新互联建站专业提供成都主机托管四川主机托管成都服务器托管四川服务器托管,支持按月付款!我们的承诺:贵族品质、平民价格,机房位于中国电信/网通/移动机房,大邑服务器托管服务有保障!

但是TFRecord数据是二进制格式,没法直接查看。因此,如何能够方便的查看TFRecord格式和数据,就显得尤为重要了。

为什么需要查看TFReocrd数据?首先我们先看下常规的写入和读取TFRecord数据的关键过程。

# 1. 写入过程
# 一张图片,我写入了其内容,label,长和宽几个信息
tf_example = tf.train.Example(
    features=tf.train.Features(feature={
      'encoded': bytes_feature(encoded_jpg),
      'label': int64_feature(label),
      'height': int64_feature(height),
      'width': int64_feature(width)}))
# 2. 读取过程
# 定义解析的TFRecord数据格式
def _parse_image(example_proto):
   features = {'encoded':tf.FixedLenFeature((),tf.string),
  'label': tf.FixedLenFeature((), tf.int64),
  'height': tf.FixedLenFeature((), tf.int64),
  'width': tf.FixedLenFeature((), tf.int64)
}
return tf.parse_single_example(example_proto, features)
 
# TFRecord数据按照Feature解析出对应的真实数据
ds = ds.map(lambda x : _parse_image(x), num_parallel_calls=4)

当前题目:TFRecord文件查看包含的所有Features代码-创新互联
网站URL:http://ybzwz.com/article/ggcsc.html