title: Rank mismatch: Rank of labels (received 2) should equal rank of logits minus 1 (received 2)
body: <p>I'm building DNN to predict if the object is present in the image or not. My network has two hidden layers and the last layer looks like this:</p>
  
  <pre><code>  # Output layer
    W_fc2 = weight_variable([2048, 1])
    b_fc2 = bias_variable([1])
  
    y = tf.matmul(h_fc1, W_fc2) + b_fc2
  </code></pre>
  
  <p>Then I have placeholder for labels:</p>
  
  <pre><code>y_ = tf.placeholder(tf.float32, [None, 1], 'Output')
  </code></pre>
  
  <p>I run training in batches (therefore first argument in Output layer shape is None). </p>
  
  <p>I use the following loss function:</p>
  
  <pre><code>cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(
      y[:, :1], y_[:, :1], name='xentropy')
  loss = tf.reduce_mean(cross_entropy, name='xentropy_mean')
  predict_hand = tf.greater(y, 0.5)
  correct_prediction = tf.equal(tf.to_float(predict_hand), y_)
  accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  </code></pre>
  
  <p>But in runtime I got the following error:</p>
  
  <blockquote>
    <p>Rank mismatch: Rank of labels (received 2) should equal rank of logits
    minus 1 (received 2).</p>
  </blockquote>
  
  <p>I guess I should reshape labels layer, but not sure what it expects. I looked up in <a href="https://www.tensorflow.org/versions/master/api_docs/python/nn.html#sparse_softmax_cross_entropy_with_logits" rel="noreferrer">documentation</a> and it says:</p>
  
  <blockquote>
    <p>logits: Unscaled log probabilities of rank r and shape [d_0, d_1, ...,
    d_{r-2}, num_classes] and dtype float32 or float64. labels: Tensor of
    shape [d_0, d_1, ..., d_{r-2}] and dtype int32 or int64. Each entry in
    labels must be an index in [0, num_classes).</p>
  </blockquote>
  
  <p>If I have just single class, what my labels should look like (now it is just 0 or 1)? Any help appreciated</p>