title: Confusion Matrix with Tensorflow
body: <p>I am using finetune AlexNet architecture written by @kratzert on my own dataset which, works properly (I got the code from here: <a href="https://github.com/kratzert/finetune_alexnet_with_tensorflow" rel="nofollow noreferrer">https://github.com/kratzert/finetune_alexnet_with_tensorflow</a>) and I want to figure out how to build confusion matrix from his code. I have tried to use <code>tf.confusion_matrix(labels, predictions, num_classes)</code> to build confusion matrix but I can't. I am confused what should be the values for labels and predictions, I mean, I know what should be but each time I feed these value got an error. Can anyone help me on this or have a look at the code (above link) and guide me?</p>
  
  <p>I added these two lines in finetune.py exactly after calculating accuracy to make the labels and the predictions as the number of the class.</p>
  
  <pre><code>with tf.name_scope("accuracy"):
      correct_pred = tf.equal(tf.argmax(score, 1), tf.argmax(y, 1))
      accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
  
  **true_class = tf.argmax(y, 1)
  predicted_class = tf.argmax(score, 1)**
  </code></pre>
  
  <p>and I have added <code>tf.confusion_matrix()</code> inside my session at the very bottom before saving checkpoint of the model</p>
  
  <pre><code>for _ in range(val_batches_per_epoch):
  
      img_batch, label_batch = sess.run(next_batch)
  
  
      acc, cost = sess.run([accuracy, loss], feed_dict={x: img_batch,
                                                      y: label_batch,
                                                      keep_prob: 1.})
      test_acc += acc
      test_count += 1
  
  test_acc /= test_count
  print("{} Validation Accuracy = {:.4f} -- Validation Loss = {:.4f}".format(datetime.now(),test_acc, cost))
  
  print("{} Saving checkpoint of model...".format(datetime.now()))
  
  **print(sess.run(tf.confusion_matrix(true_class, predicted_class, num_classes)))**
  
  # save checkpoint of the model
  checkpoint_name = os.path.join(checkpoint_path,
                                 'model_epoch'+str(epoch+1)+'.ckpt')
  save_path = saver.save(sess, checkpoint_name)
  
  print("{} Model checkpoint saved at {}".format(datetime.now(),
                                                 checkpoint_name))
  </code></pre>
  
  <p>I have tried other places as well but each time I will get an error:</p>
  
  <pre><code>Caused by op 'Placeholder_1', defined at:
    File "/home/armin/Desktop/Alexnet_DataPipeline/finetune.py", line 85, in &lt;module&gt;
      y = tf.placeholder(tf.float32, [batch_size, num_classes])
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py", line 1777, in placeholder
      return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 4521, in placeholder
      "Placeholder", dtype=dtype, shape=shape, name=name)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
      op_def=op_def)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3290, in create_op
      op_def=op_def)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1654, in __init__
      self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access
  
  InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [128,3]
  </code></pre>
  
  <p>any help will be appreciated, Thanks.</p>