def convert_to_tfrecords(dataset, num_shards, basename, example_fn):
  """Convert a dataset to sharded TFRecords.

  Args:
    dataset: List of ImageMetadata.
    num_shards: Number of randomized shards to write dataset to.
    basename: Base name to write shards to (/path/name-xxxxx-of-yyyyy).
    example_fn: Returns Example proto given example metadata.
  """
  # Shuffle the ordering of images.
  np.random.seed(12345)
  np.random.shuffle(dataset)

  # Break dataset into num_shards.
  size = int(math.ceil(len(dataset) / num_shards))
  shards = [dataset[i:i + size] for i in range(0, len(dataset), size)]

  # Map with multithreading.
  tf.logging.info("Processing %d shards", num_shards)
  num_threads = min([num_shards, MAX_THREADS])
  workers = multiprocessing.pool.ThreadPool(num_threads)
  shard_name = basename + "-%.5d-of-" + "%.5d" % num_shards
  map_fn = functools.partial(
      convert_shard,
      shard_name_fn=lambda i: shard_name % i,
      example_fn=example_fn)
  workers.map(map_fn, enumerate(shards))
  tf.logging.info("Finished %d shards.", num_shards)
Convert a dataset to sharded TFRecords.

  Args:
    dataset: List of ImageMetadata.
    num_shards: Number of randomized shards to write dataset to.
    basename: Base name to write shards to (/path/name-xxxxx-of-yyyyy).
    example_fn: Returns Example proto given example metadata.
  
language/capwap/utils/io_utils.py