How to get the total number of entries contained in a TFRecord file?
<p>I am able to write and read TFrecord files with tensorflow. How can I quickly get the total number of entries contained in a TFRecord file? Is there any API to get the count?</p>

<p>The <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/python_io.html#tfrecords-format-details" rel="nofollow">TFRecords file format</a> is basically a sequence of structures in the form:</p>

<pre><code>struct TFRecords {
    uint64_t length;
    uint32_t length_checksum;
    uint8_t data[length];
    uint32_t data_checksum;
} Ã N
</code></pre>

<p>There is no metadata to tell how many entries are there, so the only reliable way to get the total is to read the whole file (thus no APIs to quickly get the total)  and then call <code>num_records_produced()</code>.</p>

<p>You could write custom metadata containing that number as the first record when producing the TFRecords.</p>

<p>If you are sure that every record has the same length, then you could get the number of entries as <code>decompressed_file_size / (length_of_each_record + 16)</code>.</p>

python tensorflow