TFRecord - Diffrentiate between Example & SequenceExample

34 Views Asked by At

If I have a TFRecord file, how do I find if the underlying proto is Example vs SequenceExample?

1

There are 1 best solutions below

0
Sagar On

Example and SequenceExample are protocol types in the TFRecord format.

An Example is a standard proto storing data for training and inference.

A SequenceExample represents a sequence of features and some context and it is designed to handle sequence of data, which can be useful for task like sequence to sequence models.

How we need to find if the underlying proto is Example or SequenceExample, we can use the tf.train.Example and tf.train.SequenceExample classes to parse the contents of the TFRecord file.

Please find the below sample code for parse the record.

   # parse the record

    example=tf.train.Example()
    example.ParseFromString(record)
    
    sequence_example=tf.train.SequenceExample()
    sequence_example.PraseFromString(record)

Once we parse we can check its an Example or SequenceExample.

For more information Kindly go through this links for both Example tf.train.Example and SequenceExample tf.train.SequenceExample.