当前位置:   article > 正文

基于深度学习神经网络MTCNN的人脸检测系统源码_mtcnn代码

mtcnn代码

一. mtcnn概述

        MTCNN,英文全称是Multi-task convolutional neural network,中文全称是多任务卷积神经网络,该神经网络将人脸区域检测与人脸关键点检测放在了一起。

二. mtcnn的网络结构

        mtcnn从整体上划分分为P-Net、R-Net、和O-Net三层网络结构。各层的作用直观上感受如下图所示:

        其网络结构:

三. mtcnn的网络结构代码

  1. import tensorflow as tf
  2. class PNet(tf.keras.Model):
  3. def __init__(self):
  4. super().__init__()
  5. self.conv1 = tf.keras.layers.Conv2D(10, 3, 1, name='conv1')
  6. self.prelu1 = tf.keras.layers.PReLU(shared_axes=[1,2], name="PReLU1")
  7. self.conv2 = tf.keras.layers.Conv2D(16, 3, 1, name='conv2')
  8. self.prelu2 = tf.keras.layers.PReLU(shared_axes=[1,2], name="PReLU2")
  9. self.conv3 = tf.keras.layers.Conv2D(32, 3, 1, name='conv3')
  10. self.prelu3 = tf.keras.layers.PReLU(shared_axes=[1,2], name="PReLU3")
  11. self.conv4_1 = tf.keras.layers.Conv2D(2, 1, 1, name='conv4-1')
  12. self.conv4_2 = tf.keras.layers.Conv2D(4, 1, 1, name='conv4-2')
  13. def call(self, x, training=False):
  14. out = self.prelu1(self.conv1(x))
  15. out = tf.nn.max_pool2d(out, 2, 2, padding="SAME")
  16. out = self.prelu2(self.conv2(out))
  17. out = self.prelu3(self.conv3(out))
  18. score = tf.nn.softmax(self.conv4_1(out), axis=-1)
  19. boxes = self.conv4_2(out)
  20. return boxes, score
  21. class RNet(tf.keras.Model):
  22. def __init__(self):
  23. super().__init__()
  24. self.conv1 = tf.keras.layers.Conv2D(28, 3, 1, name='conv1')
  25. self.prelu1 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu1")
  26. self.conv2 = tf.keras.layers.Conv2D(48, 3, 1, name='conv2')
  27. self.prelu2 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu2")
  28. self.conv3 = tf.keras.layers.Conv2D(64, 2, 1, name='conv3')
  29. self.prelu3 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu3")
  30. self.dense4 = tf.keras.layers.Dense(128, name='conv4')
  31. self.prelu4 = tf.keras.layers.PReLU(shared_axes=None, name="prelu4")
  32. self.dense5_1 = tf.keras.layers.Dense(2, name="conv5-1")
  33. self.dense5_2 = tf.keras.layers.Dense(4, name="conv5-2")
  34. self.flatten = tf.keras.layers.Flatten()
  35. def call(self, x, training=False):
  36. out = self.prelu1(self.conv1(x))
  37. out = tf.nn.max_pool2d(out, 3, 2, padding="SAME")
  38. out = self.prelu2(self.conv2(out))
  39. out = tf.nn.max_pool2d(out, 3, 2, padding="VALID")
  40. out = self.prelu3(self.conv3(out))
  41. out = self.flatten(out)
  42. out = self.prelu4(self.dense4(out))
  43. score = tf.nn.softmax(self.dense5_1(out), -1)
  44. boxes = self.dense5_2(out)
  45. return boxes, score
  46. class ONet(tf.keras.Model):
  47. def __init__(self):
  48. super().__init__()
  49. self.conv1 = tf.keras.layers.Conv2D(32, 3, 1, name="conv1")
  50. self.prelu1 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu1")
  51. self.conv2 = tf.keras.layers.Conv2D(64, 3, 1, name="conv2")
  52. self.prelu2 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu2")
  53. self.conv3 = tf.keras.layers.Conv2D(64, 3, 1, name="conv3")
  54. self.prelu3 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu3")
  55. self.conv4 = tf.keras.layers.Conv2D(128, 2, 1, name="conv4")
  56. self.prelu4 = tf.keras.layers.PReLU(shared_axes=[1,2], name="prelu4")
  57. self.dense5 = tf.keras.layers.Dense(256, name="conv5")
  58. self.prelu5 = tf.keras.layers.PReLU(shared_axes=None, name="prelu5")
  59. self.dense6_1 = tf.keras.layers.Dense(2 , name="conv6-1")
  60. self.dense6_2 = tf.keras.layers.Dense(4 , name="conv6-2")
  61. self.dense6_3 = tf.keras.layers.Dense(10 , name="conv6-3")
  62. self.flatten = tf.keras.layers.Flatten()
  63. def call(self, x, training=False):
  64. out = self.prelu1(self.conv1(x))
  65. out = tf.nn.max_pool2d(out, 3, 2, padding="SAME")
  66. out = self.prelu2(self.conv2(out))
  67. out = tf.nn.max_pool2d(out, 3, 2, padding="VALID")
  68. out = self.prelu3(self.conv3(out))
  69. out = tf.nn.max_pool2d(out, 2, 2, padding="SAME")
  70. out = self.prelu4(self.conv4(out))
  71. out = self.dense5(self.flatten(out))
  72. out = self.prelu5(out)
  73. score = tf.nn.softmax(self.dense6_1(out))
  74. boxes = self.dense6_2(out)
  75. lamks = self.dense6_3(out)
  76. return boxes, lamks, score

四. mtcnn的演示效果

五. 整个工程的内容

提供源代码,模型,提供GUI界面代码,主要使用方法可以参考里面的“文档说明_必看.docx”

代码的下载路径(新窗口打开链接)基于深度学习神经网络MTCNN的人脸检测系统源码

视频演示可见:基于深度学习神经网络MTCNN的GUI界面人脸检测系统源码_哔哩哔哩_bilibili

有问题可以私信或者留言,有问必答

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/325362
推荐阅读
相关标签
  

闽ICP备14008679号