【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)。

    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:

    [ { [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 !

发布了628 篇原创文章 · 获赞 863 · 访问量 185万+

猜你喜欢

转载自blog.csdn.net/JNingWei/article/details/104879886