TensorFlow - Read all examples from a TFRecords at once?

前端 未结 6 1532
野的像风
野的像风 2020-12-13 02:29

How do you read all examples from a TFRecords at once?

I\'ve been using tf.parse_single_example to read out individual examples using code similar to th

6条回答
  •  清歌不尽
    2020-12-13 03:26

    Besides, if you don't think 'tf.train.shuffle_batch' is the way you need. You may try combination of tf.TFRecordReader().read_up_to() and tf.parse_example() as well. Here's the example for your reference:

    def read_tfrecords(folder_name, bs):
        filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(glob.glob(folder_name + "/*.tfrecords")))
        reader = tf.TFRecordReader()
        _, serialized = reader.read_up_to(filename_queue, bs)
        features = tf.parse_example(
            serialized,
            features={
                'label': tf.FixedLenFeature([], tf.string),
                'image': tf.FixedLenFeature([], tf.string)
            }
        )
        record_image = tf.decode_raw(features['image'], tf.uint8)
        image = tf.reshape(record_image, [-1, 250, 151, 1])
        label = tf.cast(features['label'], tf.string)
        return image, label
    

提交回复
热议问题