title: Preserve coherence while shuffling queues in Tensorflow
body: <p>I have 3 queues, one is a FileReader supplied by a string_input_producer, two are slice_input_producers fed by a vector of int32 and a matrix of int32 respectively. They are all ordered such that, when read in sequence, they provide an image, question, and answer that forms one example.</p>
  
  <p>What I want to do is shuffle them, while preserving the relations between them.</p>
  
  <p>I've tried using shuffle_batch, but this does not preserve the relations - making it useless.</p>
  
  <p>My current code (the relevant bits):</p>
  
  <pre><code>def load_images(self,images,q_name):
      filename_queue = tf.train.string_input_producer(images,shuffle=False,name=q_name)
      reader = tf.WholeFileReader()
      key, value = reader.read(filename_queue)
      imagedata = tf.image.decode_png(value)
      imagedata = tf.cast(tf.image.resize_images(imagedata,[224,224],tf.image.ResizeMethod.NEAREST_NEIGHBOR),tf.float32)
      imagedata = tf.div(imagedata,tf.reduce_max(tf.abs(imagedata)))
      imagedata.set_shape([224,224,3])
      return key,imagedata
  
  keys[testfile],imagedata[testfile] = self.load_images(imagefiles[testfile],'test')
  keys[trainfile],imagedata[trainfile] = self.load_images(imagefiles[trainfile],'train')
  
  s_train_answer_batch,s_train_question_batch,s_train_image_batch = tf.train.batch([tf.train.slice_input_producer([answers[trainfile]],shuffle=False)[0],tf.train.slice_input_producer([questions[trainfile]],shuffle=False)[0],imagedata[trainfile]],batch_size=batch_size,capacity=batch_size*2,enqueue_many=False)
  
  feed_dict = {self.x_image:s_train_image_batch.eval(), self.x_question: s_train_question_batch.eval(), self.y_:s_train_answer_batch.eval(),self.keep_prob:keep_prob}
  
  _,ce, summary, image_summary, accuracy= sess.run([self.train_step,self.cross_entropy, self.summary_op, self.image_summary_op, self.accuracy],feed_dict=feed_dict)
  </code></pre>
  
  <p>So, to be absolutely clear: if the image, question, and answer matrices where just vectors of the numbers one to ten, I'd want the feed dictionary to look like:</p>
  
  <pre><code>q:[4,1,8,2,3,9,6,5,7],a:[4,1,8,2,3,9,6,5,7],i:[4,1,8,2,3,9,6,5,7]
  </code></pre>
  
  <p>but currently they'd look like:</p>
  
  <pre><code>q:[4,1,8,2,3,9,6,5,7],a:[7,3,1,5,6,2,4,9,8],i:[9,8,3,5,4,6,7,1,2]
  </code></pre>