Tensorflow 让张量流1


  import tensorflow as tf
  y = tf.constant([[0,0,1],[0,1,0],[0,0,1]])
  pred = tf.constant([[0.2, 0.3 , 0.5],[0.2 , 0.2 , 0.6],[0.3 , 0.3 , 0.4]])

  pred2 = tf.equal(tf.argmax(pred, 1), 2)
  #pred2_sum = tf.reduce_sum(tf.cast(pred0,tf.int32))
  real2 = tf.equal(tf.argmax(y, 1), 2)

  #accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
  with tf.Session() as sess:    
    result1 = sess.run(pred2)    
    result2 = sess.run(real2)      
    print result1,result2    

  pred2_is_true2 = 0

  for index,value in enumerate(result1):    
    if value:        
      if result2[index]: pred2_is_true2 += 1    
    else: pass

  print pred2_is_true2/float(sum(result1))

你可能感兴趣的:(Tensorflow 让张量流1)