Skip to content

Commit 5d87492

Browse files
implemented mtcnn model loading from url + expose mtcnn to global api + fixed some minor issues
1 parent 4eed7a3 commit 5d87492

21 files changed

+218
-57
lines changed

src/faceDetectionNet/FaceDetection.ts renamed to src/FaceDetection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Rect } from '../Rect';
2-
import { Dimensions } from '../types';
1+
import { Rect } from './Rect';
2+
import { Dimensions } from './types';
33

44
export class FaceDetection {
55
private _score: number

src/FullFaceDescription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FaceDetection } from './faceDetectionNet/FaceDetection';
1+
import { FaceDetection } from './FaceDetection';
22
import { FaceLandmarks68 } from './faceLandmarkNet/FaceLandmarks68';
33

44
export class FullFaceDescription {

src/drawing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FaceDetection } from '../faceDetectionNet/FaceDetection';
1+
import { FaceDetection } from '../FaceDetection';
22
import { FaceLandmarks68 } from '../faceLandmarkNet';
33
import { FaceLandmarks } from '../FaceLandmarks';
44
import { Point } from '../Point';

src/extractFaceTensors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as tf from '@tensorflow/tfjs-core';
22

3-
import { FaceDetection } from './faceDetectionNet/FaceDetection';
3+
import { FaceDetection } from './FaceDetection';
44
import { Rect } from './Rect';
55
import { toNetInput } from './toNetInput';
66
import { TNetInput } from './types';

src/extractFaces.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { FaceDetection } from './faceDetectionNet/FaceDetection';
1+
import { FaceDetection } from './FaceDetection';
22
import { Rect } from './Rect';
33
import { toNetInput } from './toNetInput';
44
import { TNetInput } from './types';
55
import { createCanvas, getContext2dOrThrow, imageTensorToCanvas } from './utils';
6-
import * as tf from '@tensorflow/tfjs-core';
76

87
/**
98
* Extracts the image regions containing the detected faces.

src/faceDetectionNet/FaceDetectionNet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as tf from '@tensorflow/tfjs-core';
22

33
import { NeuralNetwork } from '../commons/NeuralNetwork';
4+
import { FaceDetection } from '../FaceDetection';
45
import { NetInput } from '../NetInput';
56
import { Rect } from '../Rect';
67
import { toNetInput } from '../toNetInput';
78
import { TNetInput } from '../types';
89
import { extractParams } from './extractParams';
9-
import { FaceDetection } from './FaceDetection';
1010
import { loadQuantizedParams } from './loadQuantizedParams';
1111
import { mobileNetV1 } from './mobileNetV1';
1212
import { nonMaxSuppression } from './nonMaxSuppression';

src/faceDetectionNet/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { FaceDetectionNet } from './FaceDetectionNet';
22

33
export * from './FaceDetectionNet';
4-
export * from './FaceDetection';
54

6-
export function faceDetectionNet(weights: Float32Array) {
5+
export function createFaceDetectionNet(weights: Float32Array) {
76
const net = new FaceDetectionNet()
87
net.extractWeights(weights)
98
return net
9+
}
10+
11+
export function faceDetectionNet(weights: Float32Array) {
12+
console.warn('faceDetectionNet(weights: Float32Array) will be deprecated in future, use createFaceDetectionNet instead')
13+
return createFaceDetectionNet(weights)
1014
}

src/faceDetectionNet/loadQuantizedParams.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { tf } from '..';
1+
import * as tf from '@tensorflow/tfjs-core';
2+
23
import { disposeUnusedWeightTensors } from '../commons/disposeUnusedWeightTensors';
34
import { extractWeightEntryFactory } from '../commons/extractWeightEntryFactory';
4-
import { isTensor1D, isTensor3D, isTensor4D } from '../commons/isTensor';
5+
import { isTensor3D } from '../commons/isTensor';
56
import { loadWeightMap } from '../commons/loadWeightMap';
67
import { ConvParams, ParamMapping } from '../commons/types';
78
import { BoxPredictionParams, MobileNetV1, NetParams, PointwiseConvParams, PredictionLayerParams } from './types';

src/faceLandmarkNet/FaceLandmarks68.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { getCenterPoint } from '../commons/getCenterPoint';
2-
import { FaceDetection } from '../faceDetectionNet/FaceDetection';
2+
import { FaceDetection } from '../FaceDetection';
33
import { FaceLandmarks } from '../FaceLandmarks';
44
import { IPoint, Point } from '../Point';
55
import { Rect } from '../Rect';
6-
import { Dimensions } from '../types';
76

87
// face alignment constants
98
const relX = 0.5
@@ -70,7 +69,7 @@ export class FaceLandmarks68 extends FaceLandmarks {
7069
* @returns The bounding box of the aligned face.
7170
*/
7271
public align(
73-
detection?: Rect
72+
detection?: FaceDetection | Rect
7473
): Rect {
7574
if (detection) {
7675
const box = detection instanceof FaceDetection

src/faceLandmarkNet/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import { FaceLandmarkNet } from './FaceLandmarkNet';
33
export * from './FaceLandmarkNet';
44
export * from './FaceLandmarks68';
55

6-
export function faceLandmarkNet(weights: Float32Array) {
6+
export function createFaceLandmarkNet(weights: Float32Array) {
77
const net = new FaceLandmarkNet()
88
net.extractWeights(weights)
99
return net
10+
}
11+
12+
export function faceLandmarkNet(weights: Float32Array) {
13+
console.warn('faceLandmarkNet(weights: Float32Array) will be deprecated in future, use createFaceLandmarkNet instead')
14+
return createFaceLandmarkNet(weights)
1015
}

0 commit comments

Comments
 (0)