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/image_id': _int64_feature(image.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/image_id' : _int64_feature ( image . 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
builds a sequenceexample proto for an image-caption pair .