(image, decoder, vocab)
return sequence_example
Builds a SequenceExample proto for an image-caption pair.
    Args:
      image: An ImageMetadata object.
      decoder: An ImageDecoder object.
      vocab: A Vocabulary object.
    Returns:
      A SequenceExample proto.
Builds a SequenceExample proto for an image-caption pair.
    Args:
      image: An ImageMetadata object.
      decoder: An ImageDecoder object.
      vocab: A Vocabulary object.
    Returns:
      A SequenceExample proto.
Builds a SequenceExample proto for an image - caption pair . Args : image : An ImageMetadata object . decoder : An ImageDecoder object . vocab : A Vocabulary object . Returns : A SequenceExample proto .
def _to_sequence_example(image, decoder, vocab):
    """Builds a SequenceExample proto for an image-caption pair.
    Args:
      image: An ImageMetadata object.
      decoder: An ImageDecoder object.
      vocab: A Vocabulary object.
    Returns:
      A SequenceExample proto.
    """
    with tf.gfile.FastGFile(image.filename, "r") as f:
        encoded_image = f.read()

    try:
        decoder.decode_jpeg(encoded_image)
    except (tf.errors.InvalidArgumentError, AssertionError):
        print("Skipping file with invalid JPEG data: %s" % image.filename)
        return
    context = tf.train.Features(feature={
        "image/id": _int64_feature(image.id),
        "image/data": _bytes_feature(encoded_image),
    })

    assert len(image.captions) == 1
    caption = image.captions[0]
    caption_ids = [vocab.word_to_id(word) for word in caption]
    feature_lists = tf.train.FeatureLists(feature_list={
        "image/caption": _bytes_feature_list(caption),
        "image/caption_ids": _int64_feature_list(caption_ids)
    })
    sequence_example = tf.train.SequenceExample(
        context=context, feature_lists=feature_lists)

    return sequence_example
def _to_sequence_example ( image , decoder , vocab ) : with tf . gfile . FastGFile ( image . filename , "r" ) as f : encoded_image = f . read ( ) try : decoder . decode_jpeg ( encoded_image ) except ( tf . errors . InvalidArgumentError , AssertionError ) : print ( "Skipping file with invalid JPEG data: %s" % image . filename ) return context = tf . train . Features ( feature = { "image/id" : _int64_feature ( image . id ) , "image/data" : _bytes_feature ( encoded_image ) , } ) assert len ( image . captions ) == 1 caption = image . captions [ 0 ] caption_ids = [ vocab . word_to_id ( word ) for word in caption ] feature_lists = tf . train . FeatureLists ( feature_list = { "image/caption" : _bytes_feature_list ( caption ) , "image/caption_ids" : _int64_feature_list ( caption_ids ) } ) sequence_example = tf . train . SequenceExample ( context = context , feature_lists = feature_lists ) return sequence_example