title: Output Tensor Wrong Shape When Parsing TFRecord
body: <p>When I attempt to parse a TFRecord file I am getting the following error:</p>
  
  <pre><code>(&lt;tf.Tensor 'ParseSingleExample/Squeeze_tokens:0' shape=() dtype=int64&gt;, &lt;tf.Tensor 'ParseSingleExample/Squeeze_labels:0' shape=() dtype=int64&gt;)
  W tensorflow/core/framework/op_kernel.cc:940] Invalid argument: Name: &lt;unknown&gt;, Key: tokens, Index: 0.  Number of int64 values != expected.  values size: 5 but output shape: []
  </code></pre>
  
  <p>As far as I can tell the line error implies that the output tensor is the wrong shape. I have been following the information <a href="https://www.tensorflow.org/how_tos/reading_data/" rel="nofollow noreferrer">here</a> for the most part. Under the heading <strong>Standard TensorFlow format</strong> it lists two github links that both encode and parse the mnist dataset. In the file that performs the parsing there is no reference to setting the output tensors shape as far as I can tell. I'm not sure how to correct this and I have tried everything I can think of. I have included my code below. </p>
  
  <pre><code>import tensorflow as tf
  import tempfile
  import os
  
  def make_example(sequence, label):
      #converts a sequence and its labels into a SequenceExample
  
      # The object we return
      ex = tf.train.Example()
      # Feature lists for the two sequential features of our example
      fl_tokens = ex.features.feature["tokens"]
      fl_labels = ex.features.feature["labels"]
      for token in sequence:
          fl_tokens.int64_list.value.append(token)
  
      fl_labels.int64_list.value.append(label)
  
      return ex
  
  def parse_example(filename_queue):
      #reads a TFRecord into its constituent parts
  
      reader = tf.TFRecordReader()
      _, example = reader.read(filename_queue)
  
      # Parse the example
      sequence_parsed = tf.parse_single_example(
          serialized=example,
          features={
              "tokens": tf.FixedLenFeature([], dtype=tf.int64),
              "labels": tf.FixedLenFeature([], dtype=tf.int64)
          }
      )
  
      return sequence_parsed["tokens"], sequence_parsed["labels"]
  
  if __name__ == '__main__':
      sequence = [1,2,3,4,5]
      label = 1
      #################################
      # Write all examples into a TFRecords file
      #################################
      with tempfile.NamedTemporaryFile(dir=".") as fp:
          writer = tf.python_io.TFRecordWriter(fp.name)
  
          ex = make_example(sequence, label)
          writer.write(ex.SerializeToString())
          writer.close()
  
          #################################
          # Read contents of TFRecord file
          #################################
  
          filename = os.path.join(os.getcwd(), fp.name)
          filename_queue = tf.train.string_input_producer([filename])
  
          with tf.Session() as sess:
              coord = tf.train.Coordinator()
              tf.train.start_queue_runners(coord=coord)
              out_sequence, out_label = parse_example(filename_queue)
  
  
              # Print the contents of a single entry:
              v1,v2 = sess.run([out_sequence, out_label])
              print(v1,v2)
  </code></pre>
  
  <p>--</p>
  
  <p>EDIT: So I figured out that I can get rid of the error and have things work by changing the line </p>
  
  <pre><code>"tokens": tf.FixedLenFeature([], dtype=tf.int64)
  </code></pre>
  
  <p>to </p>
  
  <pre><code>"tokens": tf.FixedLenFeature([5], dtype=tf.int64)
  </code></pre>
  
  <p>This forces the shape of the output tensor. I'm still unclear why I need to specify this for the case I have presented while the example in the tensorflow directions does not. If someone could clarify I'd greatly appreciate it.</p>