mtcnn_test.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # MIT License
  2. #
  3. # Copyright (c) 2016 David Sandberg
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in all
  13. # copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. from __future__ import absolute_import
  23. from __future__ import division
  24. from __future__ import print_function
  25. import tensorflow as tf
  26. import numpy as np
  27. import align.detect_face
  28. g1 = tf.Graph()
  29. with g1.as_default():
  30. data = tf.placeholder(tf.float32, (None,None,None,3), 'input')
  31. pnet = align.detect_face.PNet({'data':data})
  32. sess1 = tf.Session(graph=g1)
  33. pnet.load('../../data/det1.npy', sess1)
  34. pnet_fun = lambda img : sess1.run(('conv4-2/BiasAdd:0', 'prob1:0'), feed_dict={'input:0':img})
  35. np.random.seed(666)
  36. img = np.random.rand(1,3,150,150)
  37. img = np.transpose(img, (0,2,3,1))
  38. np.set_printoptions(formatter={'float': '{: 0.4f}'.format})
  39. # prob1=sess1.run('prob1:0', feed_dict={data:img})
  40. # print(prob1[0,0,0,:])
  41. # conv42=sess1.run('conv4-2/BiasAdd:0', feed_dict={data:img})
  42. # print(conv42[0,0,0,:])
  43. # conv42, prob1 = pnet_fun(img)
  44. # print(prob1[0,0,0,:])
  45. # print(conv42[0,0,0,:])
  46. # [ 0.9929 0.0071] prob1, caffe
  47. # [ 0.9929 0.0071] prob1, tensorflow
  48. # [ 0.1207 -0.0116 -0.1231 -0.0463] conv4-2, caffe
  49. # [ 0.1207 -0.0116 -0.1231 -0.0463] conv4-2, tensorflow
  50. g2 = tf.Graph()
  51. with g2.as_default():
  52. data = tf.placeholder(tf.float32, (None,24,24,3), 'input')
  53. rnet = align.detect_face.RNet({'data':data})
  54. sess2 = tf.Session(graph=g2)
  55. rnet.load('../../data/det2.npy', sess2)
  56. rnet_fun = lambda img : sess2.run(('conv5-2/conv5-2:0', 'prob1:0'), feed_dict={'input:0':img})
  57. np.random.seed(666)
  58. img = np.random.rand(73,3,24,24)
  59. img = np.transpose(img, (0,2,3,1))
  60. # np.set_printoptions(formatter={'float': '{: 0.4f}'.format})
  61. #
  62. # prob1=sess2.run('prob1:0', feed_dict={data:img})
  63. # print(prob1[0,:])
  64. #
  65. # conv52=sess2.run('conv5-2/conv5-2:0', feed_dict={data:img})
  66. # print(conv52[0,:])
  67. # [ 0.9945 0.0055] prob1, caffe
  68. # [ 0.1108 -0.0038 -0.1631 -0.0890] conv5-2, caffe
  69. # [ 0.9945 0.0055] prob1, tensorflow
  70. # [ 0.1108 -0.0038 -0.1631 -0.0890] conv5-2, tensorflow
  71. g3 = tf.Graph()
  72. with g3.as_default():
  73. data = tf.placeholder(tf.float32, (None,48,48,3), 'input')
  74. onet = align.detect_face.ONet({'data':data})
  75. sess3 = tf.Session(graph=g3)
  76. onet.load('../../data/det3.npy', sess3)
  77. onet_fun = lambda img : sess3.run(('conv6-2/conv6-2:0', 'conv6-3/conv6-3:0', 'prob1:0'), feed_dict={'input:0':img})
  78. np.random.seed(666)
  79. img = np.random.rand(11,3,48,48)
  80. img = np.transpose(img, (0,2,3,1))
  81. # np.set_printoptions(formatter={'float': '{: 0.4f}'.format})
  82. #
  83. # prob1=sess3.run('prob1:0', feed_dict={data:img})
  84. # print(prob1[0,:])
  85. # print('prob1, tensorflow')
  86. #
  87. # conv62=sess3.run('conv6-2/conv6-2:0', feed_dict={data:img})
  88. # print(conv62[0,:])
  89. # print('conv6-2, tensorflow')
  90. #
  91. # conv63=sess3.run('conv6-3/conv6-3:0', feed_dict={data:img})
  92. # print(conv63[0,:])
  93. # print('conv6-3, tensorflow')
  94. # [ 0.9988 0.0012] prob1, caffe
  95. # [ 0.0446 -0.0968 -0.1091 -0.0212] conv6-2, caffe
  96. # [ 0.2429 0.6104 0.4074 0.3104 0.5939 0.2729 0.2132 0.5462 0.7863 0.7568] conv6-3, caffe
  97. # [ 0.9988 0.0012] prob1, tensorflow
  98. # [ 0.0446 -0.0968 -0.1091 -0.0212] conv6-2, tensorflow
  99. # [ 0.2429 0.6104 0.4074 0.3104 0.5939 0.2729 0.2132 0.5462 0.7863 0.7568] conv6-3, tensorflow
  100. #pnet_fun = lambda img : sess1.run(('conv4-2/BiasAdd:0', 'prob1:0'), feed_dict={'input:0':img})