(tfrecords_path, label_field_name)
return count, values
Returns the number of examples and the set of labels in a dataset.
Returns the number of examples and the set of labels in a dataset.
Returns the number of examples and the set of labels in a dataset .
def get_count_and_labels(tfrecords_path, label_field_name):
  """Returns the number of examples and the set of labels in a dataset."""
  dataset = tf.data.TFRecordDataset(tfrecords_path)

  def _parse_function(example_string):
    features = {label_field_name: tf.FixedLenFeature([], tf.int64)}
    example = tf.parse_single_example(example_string, features=features)
    label = example[label_field_name]
    return label

  dataset = dataset.map(_parse_function)
  iterator = dataset.make_one_shot_iterator()
  next_element = iterator.get_next()
  count = 0
  values = set()
  with tf.Session() as sess:
    try:
      while True:
        value = sess.run(next_element)
        count += 1
        values.add(value)
    except tf.errors.OutOfRangeError:
      pass
  return count, values
def get_count_and_labels ( tfrecords_path , label_field_name ) : dataset = tf . data . TFRecordDataset ( tfrecords_path ) def _parse_function ( example_string ) : features = { label_field_name : tf . FixedLenFeature ( [ ] , tf . int64 ) } example = tf . parse_single_example ( example_string , features = features ) label = example [ label_field_name ] return label dataset = dataset . map ( _parse_function ) iterator = dataset . make_one_shot_iterator ( ) next_element = iterator . get_next ( ) count = 0 values = set ( ) with tf . Session ( ) as sess : try : while True : value = sess . run ( next_element ) count += 1 values . add ( value ) except tf . errors . OutOfRangeError : pass return count , values