nets.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { AgeGenderNet } from '../ageGenderNet/AgeGenderNet';
  2. import { FaceExpressionNet } from '../faceExpressionNet/FaceExpressionNet';
  3. import { FaceLandmark68Net } from '../faceLandmarkNet/FaceLandmark68Net';
  4. import { FaceLandmark68TinyNet } from '../faceLandmarkNet/FaceLandmark68TinyNet';
  5. import { FaceRecognitionNet } from '../faceRecognitionNet/FaceRecognitionNet';
  6. import { Mtcnn } from '../mtcnn/Mtcnn';
  7. import { SsdMobilenetv1 } from '../ssdMobilenetv1/SsdMobilenetv1';
  8. import { TinyFaceDetector } from '../tinyFaceDetector/TinyFaceDetector';
  9. import { TinyYolov2 } from '../tinyYolov2';
  10. export var nets = {
  11. ssdMobilenetv1: new SsdMobilenetv1(),
  12. tinyFaceDetector: new TinyFaceDetector(),
  13. tinyYolov2: new TinyYolov2(),
  14. mtcnn: new Mtcnn(),
  15. faceLandmark68Net: new FaceLandmark68Net(),
  16. faceLandmark68TinyNet: new FaceLandmark68TinyNet(),
  17. faceRecognitionNet: new FaceRecognitionNet(),
  18. faceExpressionNet: new FaceExpressionNet(),
  19. ageGenderNet: new AgeGenderNet()
  20. };
  21. /**
  22. * Attempts to detect all faces in an image using SSD Mobilenetv1 Network.
  23. *
  24. * @param input The input image.
  25. * @param options (optional, default: see SsdMobilenetv1Options constructor for default parameters).
  26. * @returns Bounding box of each face with score.
  27. */
  28. export var ssdMobilenetv1 = function (input, options) {
  29. return nets.ssdMobilenetv1.locateFaces(input, options);
  30. };
  31. /**
  32. * Attempts to detect all faces in an image using the Tiny Face Detector.
  33. *
  34. * @param input The input image.
  35. * @param options (optional, default: see TinyFaceDetectorOptions constructor for default parameters).
  36. * @returns Bounding box of each face with score.
  37. */
  38. export var tinyFaceDetector = function (input, options) {
  39. return nets.tinyFaceDetector.locateFaces(input, options);
  40. };
  41. /**
  42. * Attempts to detect all faces in an image using the Tiny Yolov2 Network.
  43. *
  44. * @param input The input image.
  45. * @param options (optional, default: see TinyYolov2Options constructor for default parameters).
  46. * @returns Bounding box of each face with score.
  47. */
  48. export var tinyYolov2 = function (input, options) {
  49. return nets.tinyYolov2.locateFaces(input, options);
  50. };
  51. /**
  52. * Attempts to detect all faces in an image and the 5 point face landmarks
  53. * of each detected face using the MTCNN Network.
  54. *
  55. * @param input The input image.
  56. * @param options (optional, default: see MtcnnOptions constructor for default parameters).
  57. * @returns Bounding box of each face with score and 5 point face landmarks.
  58. */
  59. export var mtcnn = function (input, options) {
  60. return nets.mtcnn.forward(input, options);
  61. };
  62. /**
  63. * Detects the 68 point face landmark positions of the face shown in an image.
  64. *
  65. * @param inputs The face image extracted from the bounding box of a face. Can
  66. * also be an array of input images, which will be batch processed.
  67. * @returns 68 point face landmarks or array thereof in case of batch input.
  68. */
  69. export var detectFaceLandmarks = function (input) {
  70. return nets.faceLandmark68Net.detectLandmarks(input);
  71. };
  72. /**
  73. * Detects the 68 point face landmark positions of the face shown in an image
  74. * using a tinier version of the 68 point face landmark model, which is slightly
  75. * faster at inference, but also slightly less accurate.
  76. *
  77. * @param inputs The face image extracted from the bounding box of a face. Can
  78. * also be an array of input images, which will be batch processed.
  79. * @returns 68 point face landmarks or array thereof in case of batch input.
  80. */
  81. export var detectFaceLandmarksTiny = function (input) {
  82. return nets.faceLandmark68TinyNet.detectLandmarks(input);
  83. };
  84. /**
  85. * Computes a 128 entry vector (face descriptor / face embeddings) from the face shown in an image,
  86. * which uniquely represents the features of that persons face. The computed face descriptor can
  87. * be used to measure the similarity between faces, by computing the euclidean distance of two
  88. * face descriptors.
  89. *
  90. * @param inputs The face image extracted from the aligned bounding box of a face. Can
  91. * also be an array of input images, which will be batch processed.
  92. * @returns Face descriptor with 128 entries or array thereof in case of batch input.
  93. */
  94. export var computeFaceDescriptor = function (input) {
  95. return nets.faceRecognitionNet.computeFaceDescriptor(input);
  96. };
  97. /**
  98. * Recognizes the facial expressions from a face image.
  99. *
  100. * @param inputs The face image extracted from the bounding box of a face. Can
  101. * also be an array of input images, which will be batch processed.
  102. * @returns Facial expressions with corresponding probabilities or array thereof in case of batch input.
  103. */
  104. export var recognizeFaceExpressions = function (input) {
  105. return nets.faceExpressionNet.predictExpressions(input);
  106. };
  107. /**
  108. * Predicts age and gender from a face image.
  109. *
  110. * @param inputs The face image extracted from the bounding box of a face. Can
  111. * also be an array of input images, which will be batch processed.
  112. * @returns Predictions with age, gender and gender probability or array thereof in case of batch input.
  113. */
  114. export var predictAgeAndGender = function (input) {
  115. return nets.ageGenderNet.predictAgeAndGender(input);
  116. };
  117. export var loadSsdMobilenetv1Model = function (url) { return nets.ssdMobilenetv1.load(url); };
  118. export var loadTinyFaceDetectorModel = function (url) { return nets.tinyFaceDetector.load(url); };
  119. export var loadMtcnnModel = function (url) { return nets.mtcnn.load(url); };
  120. export var loadTinyYolov2Model = function (url) { return nets.tinyYolov2.load(url); };
  121. export var loadFaceLandmarkModel = function (url) { return nets.faceLandmark68Net.load(url); };
  122. export var loadFaceLandmarkTinyModel = function (url) { return nets.faceLandmark68TinyNet.load(url); };
  123. export var loadFaceRecognitionModel = function (url) { return nets.faceRecognitionNet.load(url); };
  124. export var loadFaceExpressionModel = function (url) { return nets.faceExpressionNet.load(url); };
  125. export var loadAgeGenderModel = function (url) { return nets.ageGenderNet.load(url); };
  126. // backward compatibility
  127. export var loadFaceDetectionModel = loadSsdMobilenetv1Model;
  128. export var locateFaces = ssdMobilenetv1;
  129. export var detectLandmarks = detectFaceLandmarks;
  130. //# sourceMappingURL=nets.js.map