mtcnn_test_pnet_dbg.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from __future__ import absolute_import
  2. from __future__ import division
  3. from __future__ import print_function
  4. import tensorflow as tf
  5. import numpy as np
  6. import scipy.io as io
  7. import align.detect_face
  8. #ref = io.loadmat('pnet_dbg.mat')
  9. with tf.Graph().as_default():
  10. sess = tf.Session()
  11. with sess.as_default():
  12. with tf.variable_scope('pnet'):
  13. # data = tf.placeholder(tf.float32, (None,None,None,3), 'input')
  14. data = tf.placeholder(tf.float32, (1,1610, 1901,3), 'input')
  15. pnet = align.detect_face.PNet({'data':data})
  16. pnet.load('../../data/det1.npy', sess)
  17. # with tf.variable_scope('rnet'):
  18. # data = tf.placeholder(tf.float32, (None,24,24,3), 'input')
  19. # rnet = align.detect_face.RNet({'data':data})
  20. # rnet.load('../../data/det2.npy', sess)
  21. # with tf.variable_scope('onet'):
  22. # data = tf.placeholder(tf.float32, (None,48,48,3), 'input')
  23. # onet = align.detect_face.ONet({'data':data})
  24. # onet.load('../../data/det3.npy', sess)
  25. pnet_fun = lambda img : sess.run(('pnet/conv4-2/BiasAdd:0', 'pnet/prob1:0'), feed_dict={'pnet/input:0':img})
  26. # rnet_fun = lambda img : sess.run(('rnet/conv5-2/conv5-2:0', 'rnet/prob1:0'), feed_dict={'rnet/input:0':img})
  27. # onet_fun = lambda img : sess.run(('onet/conv6-2/conv6-2:0', 'onet/conv6-3/conv6-3:0', 'onet/prob1:0'), feed_dict={'onet/input:0':img})
  28. ref = io.loadmat('pnet_dbg.mat')
  29. img_x = np.expand_dims(ref['im_data'], 0)
  30. img_y = np.transpose(img_x, (0,2,1,3))
  31. out = pnet_fun(img_y)
  32. out0 = np.transpose(out[0], (0,2,1,3))
  33. out1 = np.transpose(out[1], (0,2,1,3))
  34. #np.where(abs(out0[0,:,:,:]-ref['out0'])>1e-18)
  35. qqq3 = np.where(abs(out1[0,:,:,:]-ref['out1'])>1e-7) # 3390 diffs with softmax2
  36. print(qqq3[0].shape)
  37. np.set_printoptions(formatter={'float': '{: 0.4f}'.format})
  38. # prob1=sess1.run('prob1:0', feed_dict={data:img})
  39. # print(prob1[0,0,0,:])
  40. # conv42=sess1.run('conv4-2/BiasAdd:0', feed_dict={data:img})
  41. # print(conv42[0,0,0,:])
  42. # conv42, prob1 = pnet_fun(img)
  43. # print(prob1[0,0,0,:])
  44. # print(conv42[0,0,0,:])
  45. # [ 0.9929 0.0071] prob1, caffe
  46. # [ 0.9929 0.0071] prob1, tensorflow
  47. # [ 0.1207 -0.0116 -0.1231 -0.0463] conv4-2, caffe
  48. # [ 0.1207 -0.0116 -0.1231 -0.0463] conv4-2, tensorflow
  49. # g2 = tf.Graph()
  50. # with g2.as_default():
  51. # data = tf.placeholder(tf.float32, (None,24,24,3), 'input')
  52. # rnet = align.detect_face.RNet({'data':data})
  53. # sess2 = tf.Session(graph=g2)
  54. # rnet.load('../../data/det2.npy', sess2)
  55. # rnet_fun = lambda img : sess2.run(('conv5-2/conv5-2:0', 'prob1:0'), feed_dict={'input:0':img})
  56. # np.random.seed(666)
  57. # img = np.random.rand(73,3,24,24)
  58. # img = np.transpose(img, (0,2,3,1))
  59. # np.set_printoptions(formatter={'float': '{: 0.4f}'.format})
  60. #
  61. # prob1=sess2.run('prob1:0', feed_dict={data:img})
  62. # print(prob1[0,:])
  63. #
  64. # conv52=sess2.run('conv5-2/conv5-2:0', feed_dict={data:img})
  65. # print(conv52[0,:])
  66. # [ 0.9945 0.0055] prob1, caffe
  67. # [ 0.1108 -0.0038 -0.1631 -0.0890] conv5-2, caffe
  68. # [ 0.9945 0.0055] prob1, tensorflow
  69. # [ 0.1108 -0.0038 -0.1631 -0.0890] conv5-2, tensorflow
  70. # g3 = tf.Graph()
  71. # with g3.as_default():
  72. # data = tf.placeholder(tf.float32, (None,48,48,3), 'input')
  73. # onet = align.detect_face.ONet({'data':data})
  74. # sess3 = tf.Session(graph=g3)
  75. # onet.load('../../data/det3.npy', sess3)
  76. # onet_fun = lambda img : sess3.run(('conv6-2/conv6-2:0', 'conv6-3/conv6-3:0', 'prob1:0'), feed_dict={'input:0':img})
  77. # np.random.seed(666)
  78. # img = np.random.rand(11,3,48,48)
  79. # img = np.transpose(img, (0,2,3,1))
  80. # np.set_printoptions(formatter={'float': '{: 0.4f}'.format})
  81. #
  82. # prob1=sess3.run('prob1:0', feed_dict={data:img})
  83. # print(prob1[0,:])
  84. # print('prob1, tensorflow')
  85. #
  86. # conv62=sess3.run('conv6-2/conv6-2:0', feed_dict={data:img})
  87. # print(conv62[0,:])
  88. # print('conv6-2, tensorflow')
  89. #
  90. # conv63=sess3.run('conv6-3/conv6-3:0', feed_dict={data:img})
  91. # print(conv63[0,:])
  92. # print('conv6-3, tensorflow')
  93. # [ 0.9988 0.0012] prob1, caffe
  94. # [ 0.0446 -0.0968 -0.1091 -0.0212] conv6-2, caffe
  95. # [ 0.2429 0.6104 0.4074 0.3104 0.5939 0.2729 0.2132 0.5462 0.7863 0.7568] conv6-3, caffe
  96. # [ 0.9988 0.0012] prob1, tensorflow
  97. # [ 0.0446 -0.0968 -0.1091 -0.0212] conv6-2, tensorflow
  98. # [ 0.2429 0.6104 0.4074 0.3104 0.5939 0.2729 0.2132 0.5462 0.7863 0.7568] conv6-3, tensorflow
  99. #pnet_fun = lambda img : sess1.run(('conv4-2/BiasAdd:0', 'prob1:0'), feed_dict={'input:0':img})