nets.js 6.4 KB

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