title: how to create confusion matrix for classification in tensorflow
body: <p>I have CNN model which has 4 output nodes, and I am trying to compute the confusion matrix so that i can know the individual class accuracy. I am able to compute the overall accuracy.
  In the link <a href="https://stackoverflow.com/questions/35756710/how-do-i-create-confusion-matrix-of-predicted-and-ground-truth-labels-with-tenso">here</a>, Igor Valantic gave a function which can compute the confusion matrix variables. 
  it gives me an error at <code>correct_prediction = tf.nn.in_top_k(logits, labels, 1, name="correct_answers")</code> and the error is <code>TypeError: DataType float32 for attr 'T' not in list of allowed values: int32, int64</code></p>
  
  <p>I have tried typecasting logits to int32 inside function mentioned <code>def evaluation(logits, labels)</code>, it gives another error at computing <code>correct_prediction = ...</code> as   <code>TypeError:Input 'predictions' of 'InTopK' Op has type int32 that does not match expected type of float32</code> </p>
  
  <p>how to calculate this confusion matrix ?</p>
  
  <pre><code>sess = tf.Session()
  model = dimensions() # CNN input weights are calculated 
  data_train, data_test, label_train, label_test =  load_data(files_test2,folder)
  data_train, data_test, = reshapedata(data_train, data_test, model)
  # input output placeholders
  x  = tf.placeholder(tf.float32, [model.BATCH_SIZE, model.input_width,model.input_height,model.input_depth]) # last column = 1 
  y_ = tf.placeholder(tf.float32, [model.BATCH_SIZE, model.No_Classes])
  p_keep_conv = tf.placeholder("float")
  # 
  y  = mycnn(x,model, p_keep_conv)
  # loss
  cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))
  # train step
  train_step = tf.train.AdamOptimizer(1e-3).minimize(cost)
  correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
  accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  true_positives, false_positives, true_negatives, false_negatives = evaluation(y,y_)
  lossfun = np.zeros(STEPS)
  sess.run(tf.global_variables_initializer())
  
  for i in range(STEPS):
      image_batch, label_batch = batchdata(data_train, label_train, model.BATCH_SIZE)
      epoch_loss = 0
      for j in range(model.BATCH_SIZE):
          sess.run(train_step, feed_dict={x: image_batch, y_: label_batch, p_keep_conv:1.0})
          c = sess.run( cost, feed_dict={x: image_batch, y_: label_batch, p_keep_conv: 1.0})
          epoch_loss += c
      lossfun[i] = epoch_loss
      print('Epoch',i,'completed out of',STEPS,'loss:',epoch_loss )
   TP,FP,TN,FN = sess.run([true_positives, false_positives, true_negatives,  false_negatives], feed_dict={x: image_batch, y_: label_batch, p_keep_conv:1.0})
  </code></pre>
  
  <p>this is my code snippet</p>