(name, images, vocab, num_shards)
Processes a complete data set and saves it as a TFRecord.
    Args:
      name: Unique identifier specifying the dataset.
      images: List of ImageMetadata.
      vocab: A Vocabulary object.
      num_shards: Integer number of shards for the output files.
Processes a complete data set and saves it as a TFRecord.
    Args:
      name: Unique identifier specifying the dataset.
      images: List of ImageMetadata.
      vocab: A Vocabulary object.
      num_shards: Integer number of shards for the output files.
Processes a complete data set and saves it as a TFRecord . Args : name : Unique identifier specifying the dataset . images : List of ImageMetadata . vocab : A Vocabulary object . num_shards : Integer number of shards for the output files .
def _process_dataset(name, images, vocab, num_shards):
    """Processes a complete data set and saves it as a TFRecord.
    Args:
      name: Unique identifier specifying the dataset.
      images: List of ImageMetadata.
      vocab: A Vocabulary object.
      num_shards: Integer number of shards for the output files.
    """
    # Break up each image into a separate entity for each caption.
    images = [ImageMetadata(image.id, image.filename, [caption])
              for image in images for caption in image.captions]

    # Shuffle the ordering of images. Make the randomization repeatable.
    random.seed(12345)
    random.shuffle(images)

    # Break the images into num_threads batches. Batch i is defined as
    # images[ranges[i][0]:ranges[i][1]].
    num_threads = min(num_shards, FLAGS.num_threads)
    spacing = np.linspace(0, len(images), num_threads + 1).astype(np.int)
    ranges = []
    threads = []
    for i in range(len(spacing) - 1):
        ranges.append([spacing[i], spacing[i + 1]])

    # Create a mechanism for monitoring when all threads are finished.
    coord = tf.train.Coordinator()

    # Create a utility for decoding JPEG images to run sanity checks.
    decoder = ImageDecoder()

    # Launch a thread for each batch.
    print("Launching %d threads for spacings: %s" % (num_threads, ranges))
    for thread_index in range(len(ranges)):
        args = (thread_index, ranges, name, images, decoder, vocab, num_shards)
        t = threading.Thread(target=_process_image_files, args=args)
        t.start()
        threads.append(t)

    # Wait for all the threads to terminate.
    coord.join(threads)
    print("%s: Finished processing all %d image-caption pairs in data set '%s'." %
          (datetime.now(), len(images), name))
def _process_dataset ( name , images , vocab , num_shards ) : # Break up each image into a separate entity for each caption. images = [ ImageMetadata ( image . id , image . filename , [ caption ] ) for image in images for caption in image . captions ] # Shuffle the ordering of images. Make the randomization repeatable. random . seed ( 12345 ) random . shuffle ( images ) # Break the images into num_threads batches. Batch i is defined as # images[ranges[i][0]:ranges[i][1]]. num_threads = min ( num_shards , FLAGS . num_threads ) spacing = np . linspace ( 0 , len ( images ) , num_threads + 1 ) . astype ( np . int ) ranges = [ ] threads = [ ] for i in range ( len ( spacing ) - 1 ) : ranges . append ( [ spacing [ i ] , spacing [ i + 1 ] ] ) # Create a mechanism for monitoring when all threads are finished. coord = tf . train . Coordinator ( ) # Create a utility for decoding JPEG images to run sanity checks. decoder = ImageDecoder ( ) # Launch a thread for each batch. print ( "Launching %d threads for spacings: %s" % ( num_threads , ranges ) ) for thread_index in range ( len ( ranges ) ) : args = ( thread_index , ranges , name , images , decoder , vocab , num_shards ) t = threading . Thread ( target = _process_image_files , args = args ) t . start ( ) threads . append ( t ) # Wait for all the threads to terminate. coord . join ( threads ) print ( "%s: Finished processing all %d image-caption pairs in data set '%s'." % ( datetime . now ( ) , len ( images ) , name ) )