首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

【tensorflow】TFRecord读写机理

1.tfrecord,写的时候是一行一行地写的,读的时候是每batch个行地读的。

2.写的时候,通过for循环(例如:img_path, cls_label = img_paths[i], cls_labels[I])往tf.train.Example里面喂feature。 因此,tf.train.Example中的feature喂入的是单行的数据(包括一个img_path、及其对应的encode_img、cls_label、pts_label)。

代码语言:javascript
复制
example = tf.train.Example(features=tf.train.Features(feature={
    'img_path': _bytes_feature(img_path),
    'encoded': _bytes_feature(image_buffer),
    'cls_label': _int64_feature(cls_label)
}))
 

可以通过print(example)查看。

3.最后的数据会在tfrecord中形成一个二维list:

代码语言:javascript
复制
[ { [img_path], [img_encode], [cls_label], [pts_label] }
  { [img_path], [img_encode], [cls_label], [pts_label] }
  { [img_path], [img_encode], [cls_label], [pts_label] }
  { [img_path], [img_encode], [cls_label], [pts_label] }
                                             … …
  { [img_path], [img_encode], [cls_label], [pts_label] } ]

list中每行,都是一个完整的数据element,element = { [img_path], [img_encode], [cls_label], [pts_label] }

4.具体地,element = { [b’\path\to\img_1.jpg’], [\df\sdf\df\df\dfsxc\d], [1], [21.2, 34.6, 45.1, 56.7] }

5.element中的每一个单项都是 type list,所以写入 _int64_feature、_float_feature、_bytes_feature 时,一定是一个 一维list !

下一篇
举报
领券