Obtaining total number of records from .tfrecords file in Tensorflow

后端 未结 4 1930
南方客
南方客 2020-12-13 10:27

Is it possible for obtain the total number of records from a .tfrecords file ? Related to this, how does one generally keep track of the number of epochs that h

4条回答
  •  时光说笑
    2020-12-13 10:46

    As per the deprecation warning on tf_record_iterator, we can also use eager execution to count records.

    #!/usr/bin/env python
    from __future__ import print_function
    
    import tensorflow as tf
    import sys
    
    assert len(sys.argv) == 2, \
        "USAGE: {} ".format(sys.argv[0])
    
    tf.enable_eager_execution()
    
    input_pattern = sys.argv[1]
    
    # Expand glob if there is one
    input_files = tf.io.gfile.glob(input_pattern)
    
    # Create the dataset
    data_set = tf.data.TFRecordDataset(input_files)
    
    # Count the records
    records_n = sum(1 for record in data_set)
    
    print("records_n = {}".format(records_n))
    

提交回复
热议问题