def batch_with_dynamic_pad(images_and_captions, batch_size, queue_capacity, add_summaries=True):
 enqueue_list = []
 for (image, caption) in images_and_captions:
  caption_length = tf.shape(caption)[0]
  input_length = tf.expand_dims(tf.sub(caption_length, 1), 0)
  input_seq = tf.slice(caption, [0], input_length)
  target_seq = tf.slice(caption, [1], input_length)
  indicator = tf.ones(input_length, dtype=tf.int32)
  enqueue_list.append([image, input_seq, target_seq, indicator])
 (images, input_seqs, target_seqs, mask) = tf.train.batch_join(enqueue_list, batch_size=batch_size, capacity=queue_capacity, dynamic_pad=True, name='batch_and_pad')
 if add_summaries:
  lengths = tf.add(tf.reduce_sum(mask, 1), 1)
  tf.scalar_summary('caption_length/batch_min', tf.reduce_min(lengths))
  tf.scalar_summary('caption_length/batch_max', tf.reduce_max(lengths))
  tf.scalar_summary('caption_length/batch_mean', tf.reduce_mean(lengths))
 return (images, input_seqs, target_seqs, mask)

def batch_with_dynamic_pad ( images_and_captions , batch_size , queue_capacity , add_summaries = True ) : enqueue_list = [ ] for ( image , caption ) in images_and_captions : caption_length = tf . shape ( caption ) [ 0 ] input_length = tf . expand_dims ( tf . sub ( caption_length , 1 ) , 0 ) input_seq = tf . slice ( caption , [ 0 ] , input_length ) target_seq = tf . slice ( caption , [ 1 ] , input_length ) indicator = tf . ones ( input_length , dtype = tf . int32 ) enqueue_list . append ( [ image , input_seq , target_seq , indicator ] ) ( images , input_seqs , target_seqs , mask ) = tf . train . batch_join ( enqueue_list , batch_size = batch_size , capacity = queue_capacity , dynamic_pad = True , name = 'batch_and_pad' ) if add_summaries : lengths = tf . add ( tf . reduce_sum ( mask , 1 ) , 1 ) tf . scalar_summary ( 'caption_length/batch_min' , tf . reduce_min ( lengths ) ) tf . scalar_summary ( 'caption_length/batch_max' , tf . reduce_max ( lengths ) ) tf . scalar_summary ( 'caption_length/batch_mean' , tf . reduce_mean ( lengths ) ) return ( images , input_seqs , target_seqs , mask )
batches input images and captions .