Unverified Commit 64cf04a4 by justadudewhohacks Committed by GitHub

Merge pull request #8 from justadudewhohacks/face-recognition-center-face

Face recognition center face
parents cc99df49 fea53c37
import * as tf from '@tensorflow/tfjs-core';
import { getImageTensor } from './transformInputs';
import { getImageTensor } from './getImageTensor';
/**
* Extracts the tensors of the image regions containing the detected faces.
* Returned tensors have to be disposed manually once you don't need them anymore!
......
{"version":3,"file":"extractFaceTensors.js","sourceRoot":"","sources":["../src/extractFaceTensors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;;;;;;;;GAUG;AACH,MAAM,6BACJ,KAAuC,EACvC,UAAiC;IAEjC,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QAEvC,sBAAsB;QAChB,IAAA,oBAA+D,EAA9D,iBAAS,EAAE,iBAAS,EAAE,gBAAQ,EAAE,mBAAW,CAAmB;QAErE,IAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,UAAA,GAAG;YAC9B,IAAA,yCAA8D,EAA5D,QAAC,EAAE,QAAC,EAAE,gBAAK,EAAE,kBAAM,CAAyC;YACpE,OAAO,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAA;QAC3E,CAAC,CAAC,CAAA;QAEF,OAAO,WAAW,CAAA;IACpB,CAAC,CAAC,CAAA;AACJ,CAAC"}
\ No newline at end of file
{"version":3,"file":"extractFaceTensors.js","sourceRoot":"","sources":["../src/extractFaceTensors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD;;;;;;;;;;GAUG;AACH,MAAM,6BACJ,KAAuC,EACvC,UAAiC;IAEjC,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;QAEvC,sBAAsB;QAChB,IAAA,oBAA+D,EAA9D,iBAAS,EAAE,iBAAS,EAAE,gBAAQ,EAAE,mBAAW,CAAmB;QAErE,IAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,UAAA,GAAG;YAC9B,IAAA,yCAA8D,EAA5D,QAAC,EAAE,QAAC,EAAE,gBAAK,EAAE,kBAAM,CAAyC;YACpE,OAAO,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAA;QAC3E,CAAC,CAAC,CAAA;QAEF,OAAO,WAAW,CAAA;IACpB,CAAC,CAAC,CAAA;AACJ,CAAC"}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
import * as tslib_1 from "tslib";
import * as tf from '@tensorflow/tfjs-core';
import { getImageTensor, padToSquare } from '../transformInputs';
import { getImageTensor } from '../getImageTensor';
import { padToSquare } from '../padToSquare';
import { extractParams } from './extractParams';
import { FaceDetectionResult } from './FaceDetectionResult';
import { mobileNetV1 } from './mobileNetV1';
......@@ -32,7 +33,7 @@ export function faceDetectionNet(weights) {
paddedHeightRelative = 1, paddedWidthRelative = 1;
_a = tf.tidy(function () {
var imgTensor = getImageTensor(input);
var _a = imgTensor.shape, _ = _a[0], height = _a[1], width = _a[2];
var _a = imgTensor.shape.slice(1), height = _a[0], width = _a[1];
imgTensor = padToSquare(imgTensor);
paddedHeightRelative = imgTensor.shape[1] / height;
paddedWidthRelative = imgTensor.shape[2] / width;
......
{"version":3,"file":"index.js","s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AAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;4BACtC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;4BACnB,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;yBACrB;wBAGkB,KAAA,CAAA,KAAA,KAAK,CAAA,CAAC,IAAI,CAAA;wBAAC,qBAAM,MAAM,CAAC,IAAI,EAAE,EAAA;;wBAA3C,UAAU,GAAG,cAAW,SAAmB,EAAC;wBAE5C,YAAY,GAAG,GAAG,CAAA;wBAClB,OAAO,GAAG,iBAAiB,CAC/B,KAAK,EACL,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,CACd,CAAA;wBAEK,OAAO,GAAG,OAAO;6BACpB,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,IAAI,mBAAmB,CACjC,UAAU,CAAC,GAAG,CAAC,EACf,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,oBAAoB,EACxC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,mBAAmB,EACvC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,oBAAoB,EACxC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,mBAAmB,CACxC,EANW,CAMX,CAAC,CAAA;wBAEJ,KAAK,CAAC,OAAO,EAAE,CAAA;wBACf,MAAM,CAAC,OAAO,EAAE,CAAA;wBAEhB,sBAAO,OAAO,EAAA;;;;KACf;IAED,OAAO;QACL,OAAO,SAAA;QACP,WAAW,aAAA;KACZ,CAAA;AACH,CAAC"}
\ No newline at end of file
import * as tslib_1 from "tslib";
import * as tf from '@tensorflow/tfjs-core';
import { getImageTensor, padToSquare } from '../transformInputs';
import { getImageTensor } from '../getImageTensor';
import { padToSquare } from '../padToSquare';
import { convDown } from './convLayer';
import { extractParams } from './extractParams';
import { normalize } from './normalize';
......@@ -10,8 +11,7 @@ export function faceRecognitionNet(weights) {
var params = extractParams(weights);
function forward(input) {
return tf.tidy(function () {
// TODO pad on both sides, to keep face centered
var x = padToSquare(getImageTensor(input));
var x = padToSquare(getImageTensor(input), true);
// work with 150 x 150 sized face images
if (x.shape[1] !== 150 || x.shape[2] !== 150) {
x = tf.image.resizeBilinear(x, [150, 150]);
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/faceRecognitionNet/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD,MAAM,6BAA6B,OAAqB;IAAxD,iBA6DC;IA5DC,IAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IAErC,iBAAiB,KAAuC;QACtD,OAAO,EAAE,CAAC,IAAI,CAAC;YAEb,gDAAgD;YAChD,IAAI,CAAC,GAAG,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAA;YAC1C,wCAAwC;YACxC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;gBAC5C,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;aAC3C;YACD,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;YAEhB,IAAI,GAAG,GAAG,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAA;YACz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A;KACR,CAAA;AACH,CAAC"}
\ No newline at end of file
import * as tf from '@tensorflow/tfjs-core';
import { NetInput } from './NetInput';
import { TNetInput } from './types';
export declare function getImageTensor(input: tf.Tensor | NetInput | TNetInput): tf.Tensor4D;
import * as tf from '@tensorflow/tfjs-core';
import { NetInput } from './NetInput';
export function getImageTensor(input) {
return tf.tidy(function () {
if (input instanceof tf.Tensor) {
var rank = input.shape.length;
if (rank !== 3 && rank !== 4) {
throw new Error('input tensor must be of rank 3 or 4');
}
return (rank === 3 ? input.expandDims(0) : input).toFloat();
}
var netInput = input instanceof NetInput ? input : new NetInput(input);
return tf.concat(netInput.canvases.map(function (canvas) {
return tf.fromPixels(canvas).expandDims(0).toFloat();
}));
});
}
//# sourceMappingURL=getImageTensor.js.map
\ No newline at end of file
{"version":3,"file":"getImageTensor.js","sourceRoot":"","sources":["../src/getImageTensor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,yBAAyB,KAAuC;IACpE,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAI,KAAK,YAAY,EAAE,CAAC,MAAM,EAAE;YAC9B,IAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAA;YAC/B,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;aACvD;YAED,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAiB,CAAA;SAC3E;QAED,IAAM,QAAQ,GAAG,KAAK,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAA;QACxE,OAAO,EAAE,CAAC,MAAM,CACd,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAA,MAAM;YAC1B,OAAA,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;QAA7C,CAA6C,CAC9C,CACa,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC"}
\ No newline at end of file
import * as tf from '@tensorflow/tfjs-core';
import { euclideanDistance } from './euclideanDistance';
import { faceDetectionNet } from './faceDetectionNet';
import { faceRecognitionNet } from './faceRecognitionNet';
import { NetInput } from './NetInput';
import * as tf from '@tensorflow/tfjs-core';
export { euclideanDistance, faceDetectionNet, faceRecognitionNet, NetInput, tf };
import { padToSquare } from './padToSquare';
export { euclideanDistance, faceDetectionNet, faceRecognitionNet, NetInput, tf, padToSquare };
export * from './extractFaces';
export * from './extractFaceTensors';
export * from './utils';
import * as tf from '@tensorflow/tfjs-core';
import { euclideanDistance } from './euclideanDistance';
import { faceDetectionNet } from './faceDetectionNet';
import { faceRecognitionNet } from './faceRecognitionNet';
import { NetInput } from './NetInput';
import * as tf from '@tensorflow/tfjs-core';
export { euclideanDistance, faceDetectionNet, faceRecognitionNet, NetInput, tf };
import { padToSquare } from './padToSquare';
export { euclideanDistance, faceDetectionNet, faceRecognitionNet, NetInput, tf, padToSquare };
export * from './extractFaces';
export * from './extractFaceTensors';
export * from './utils';
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,EAAE,EACH,CAAA;AAED,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA"}
\ No newline at end of file
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,EAAE,EACF,WAAW,EACZ,CAAA;AAED,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA"}
\ No newline at end of file
import * as tf from '@tensorflow/tfjs-core';
/**
* Pads the smaller dimension of an image tensor with zeros, such that width === height.
*
* @param imgTensor The image tensor.
* @param isCenterImage (optional, default: false) If true, add padding on both sides of the image, such that the image
* @returns The padded tensor with width === height.
*/
export declare function padToSquare(imgTensor: tf.Tensor4D, isCenterImage?: boolean): tf.Tensor4D;
import * as tf from '@tensorflow/tfjs-core';
/**
* Pads the smaller dimension of an image tensor with zeros, such that width === height.
*
* @param imgTensor The image tensor.
* @param isCenterImage (optional, default: false) If true, add padding on both sides of the image, such that the image
* @returns The padded tensor with width === height.
*/
export function padToSquare(imgTensor, isCenterImage) {
if (isCenterImage === void 0) { isCenterImage = false; }
return tf.tidy(function () {
var _a = imgTensor.shape.slice(1), height = _a[0], width = _a[1];
if (height === width) {
return imgTensor;
}
var paddingAmount = Math.floor(Math.abs(height - width) * (isCenterImage ? 0.5 : 1));
var paddingAxis = height > width ? 2 : 1;
var paddingTensorShape = imgTensor.shape.slice();
paddingTensorShape[paddingAxis] = paddingAmount;
var tensorsToStack = (isCenterImage ? [tf.fill(paddingTensorShape, 0)] : [])
.concat([imgTensor, tf.fill(paddingTensorShape, 0)]);
return tf.concat(tensorsToStack, paddingAxis);
});
}
//# sourceMappingURL=padToSquare.js.map
\ No newline at end of file
{"version":3,"file":"padToSquare.js","sourceRoot":"","sources":["../src/padToSquare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,sBACJ,SAAsB,EACtB,aAA8B;IAA9B,8BAAA,EAAA,qBAA8B;IAE9B,OAAO,EAAE,CAAC,IAAI,CAAC;QAEP,IAAA,6BAA0C,EAAzC,cAAM,EAAE,aAAK,CAA4B;QAChD,IAAI,MAAM,KAAK,KAAK,EAAE;YACpB,OAAO,SAAS,CAAA;SACjB;QAED,IAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACtF,IAAM,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC1C,IAAM,kBAAkB,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAsC,CAAA;QACtF,kBAAkB,CAAC,WAAW,CAAC,GAAG,aAAa,CAAA;QAE/C,IAAM,cAAc,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3E,MAAM,CAAC,CAAC,SAAS,EAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAkB,CAAA;QACxE,OAAO,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC"}
\ No newline at end of file
import * as tf from '@tensorflow/tfjs-core';
import { NetInput } from './NetInput';
import { TNetInput } from './types';
export declare function padToSquare(imgTensor: tf.Tensor4D): tf.Tensor4D;
/**
* Pads the smaller dimension of an image tensor with zeros, such that width === height.
*
* @param imgTensor The image tensor.
* @param isCenterImage (optional, default: false) If true, add padding on both sides of the image, such that the image
* @returns The padded tensor with width === height.
*/
export declare function padToSquare(imgTensor: tf.Tensor4D, isCenterImage?: boolean): tf.Tensor4D;
export declare function getImageTensor(input: tf.Tensor | NetInput | TNetInput): tf.Tensor4D;
import * as tf from '@tensorflow/tfjs-core';
import { NetInput } from './NetInput';
export function padToSquare(imgTensor) {
/**
* Pads the smaller dimension of an image tensor with zeros, such that width === height.
*
* @param imgTensor The image tensor.
* @param isCenterImage (optional, default: false) If true, add padding on both sides of the image, such that the image
* @returns The padded tensor with width === height.
*/
export function padToSquare(imgTensor, isCenterImage) {
if (isCenterImage === void 0) { isCenterImage = false; }
return tf.tidy(function () {
var _a = imgTensor.shape, _ = _a[0], height = _a[1], width = _a[2];
var _a = imgTensor.shape.slice(1), height = _a[0], width = _a[1];
if (height === width) {
return imgTensor;
}
if (height > width) {
var pad_1 = tf.fill([1, height, height - width, 3], 0);
return tf.concat([imgTensor, pad_1], 2);
}
var pad = tf.fill([1, width - height, width, 3], 0);
return tf.concat([imgTensor, pad], 1);
var paddingAmount = Math.floor(Math.abs(height - width) * (isCenterImage ? 0.5 : 1));
var paddingAxis = height > width ? 2 : 1;
var paddingTensorShape = imgTensor.shape.slice();
paddingTensorShape[paddingAxis] = paddingAmount;
var tensorsToStack = (isCenterImage ? [tf.fill(paddingTensorShape, 0)] : [])
.concat([imgTensor, tf.fill(paddingTensorShape, 0)]);
console.log(tensorsToStack);
return tf.concat(tensorsToStack, paddingAxis);
});
}
export function getImageTensor(input) {
......
{"version":3,"file":"transformInputs.js","sourceRoot":"","sources":["../src/transformInputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,sBAAsB,SAAsB;IAChD,OAAO,EAAE,CAAC,IAAI,CAAC;QAEP,IAAA,oBAAoC,EAAnC,SAAC,EAAE,cAAM,EAAE,aAAK,CAAmB;QAC1C,IAAI,MAAM,KAAK,KAAK,EAAE;YACpB,OAAO,SAAS,CAAA;SACjB;QAED,IAAI,MAAM,GAAG,KAAK,EAAE;YAClB,IAAM,KAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAgB,CAAA;YACrE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,KAAG,CAAC,EAAE,CAAC,CAAC,CAAA;SACtC;QACD,IAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAgB,CAAA;QACpE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,yBAAyB,KAAuC;IACpE,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAI,KAAK,YAAY,EAAE,CAAC,MAAM,EAAE;YAC9B,IAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAA;YAC/B,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE;gBAC5B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAA;aACvD;YAED,OAAO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CAAC,CAAC,OAAO,EAAE;QAA7C,CAA6C,CAC9C,CACa,CAAA;IAClB,CAAC,CAAC,CAAA;AACJ,CAAC"}
\ No newline at end of file
......@@ -25,28 +25,39 @@ async function initFaceRecognitionNet() {
}
// fetch first image of each class and compute their descriptors
async function initTrainDescriptorsByClass(net) {
async function initTrainDescriptorsByClass(net, numImagesForTraining = 1) {
const maxAvailableImagesPerClass = 5
numImagesForTraining = Math.min(numImagesForTraining, maxAvailableImagesPerClass)
return Promise.all(classes.map(
async className => {
const img = await facerecognition.bufferToImage(
await fetchImage(getFaceImageUri(className, 1))
)
const descriptor = await net.computeFaceDescriptor(img)
const descriptors = []
for (let i = 1; i < (numImagesForTraining + 1); i++) {
const img = await facerecognition.bufferToImage(
await fetchImage(getFaceImageUri(className, i))
)
descriptors.push(await net.computeFaceDescriptor(img))
}
return {
descriptor,
descriptors,
className
}
}
))
}
function getBestMatch(allDescriptors, queryDescriptor) {
return allDescriptors
function getBestMatch(descriptorsByClass, queryDescriptor) {
function computeMeanDistance(descriptorsOfClass) {
return facerecognition.round(
descriptorsOfClass
.map(d => facerecognition.euclideanDistance(d, queryDescriptor))
.reduce((d1, d2) => d1 + d2, 0)
/ (descriptorsOfClass.length || 1)
)
}
return descriptorsByClass
.map(
({ descriptor, className }) => ({
distance: facerecognition.round(
facerecognition.euclideanDistance(descriptor, queryDescriptor)
),
({ descriptors, className }) => ({
distance: computeMeanDistance(descriptors),
className
})
)
......
......@@ -41,7 +41,7 @@
</div>
<script>
const threshold = 0.6
const threshold = 0.8
let minConfidence = 0.7
let detectionNet, recognitionNet
let trainDescriptorsByClass = []
......@@ -71,7 +71,7 @@
const detectionsForSize = detections.map(det => det.forSize(width, height))
facerecognition.drawDetection('overlay', detectionsForSize, { withScore: false })
const faceTensors = await facerecognition.extractFaceTensors(input, detections)
const faceTensors = (await facerecognition.extractFaceTensors(input, detections))
const descriptors = await Promise.all(faceTensors.map(t => recognitionNet.computeFaceDescriptor(t)))
// free memory for face image tensors after we computed their descriptors
......@@ -94,7 +94,7 @@
async function run() {
detectionNet = await initFaceDetectionNet()
recognitionNet = await initFaceRecognitionNet()
trainDescriptorsByClass = await initTrainDescriptorsByClass(recognitionNet)
trainDescriptorsByClass = await initTrainDescriptorsByClass(recognitionNet, 1)
$('#loader').hide()
onSelectionChanged($('#selectList select').val())
}
......
......@@ -2,7 +2,7 @@ import * as tf from '@tensorflow/tfjs-core';
import { FaceDetectionResult } from './faceDetectionNet/FaceDetectionResult';
import { NetInput } from './NetInput';
import { getImageTensor } from './transformInputs';
import { getImageTensor } from './getImageTensor';
import { TNetInput } from './types';
/**
......
import * as tf from '@tensorflow/tfjs-core';
import { getImageTensor } from '../getImageTensor';
import { NetInput } from '../NetInput';
import { getImageTensor, padToSquare } from '../transformInputs';
import { padToSquare } from '../padToSquare';
import { TNetInput } from '../types';
import { extractParams } from './extractParams';
import { FaceDetectionResult } from './FaceDetectionResult';
......@@ -49,7 +50,7 @@ export function faceDetectionNet(weights: Float32Array) {
} = tf.tidy(() => {
let imgTensor = getImageTensor(input)
const [_, height, width] = imgTensor.shape
const [height, width] = imgTensor.shape.slice(1)
imgTensor = padToSquare(imgTensor)
paddedHeightRelative = imgTensor.shape[1] / height
......
import * as tf from '@tensorflow/tfjs-core';
import { getImageTensor } from '../getImageTensor';
import { NetInput } from '../NetInput';
import { getImageTensor, padToSquare } from '../transformInputs';
import { padToSquare } from '../padToSquare';
import { TNetInput } from '../types';
import { convDown } from './convLayer';
import { extractParams } from './extractParams';
......@@ -14,8 +15,7 @@ export function faceRecognitionNet(weights: Float32Array) {
function forward(input: tf.Tensor | NetInput | TNetInput) {
return tf.tidy(() => {
// TODO pad on both sides, to keep face centered
let x = padToSquare(getImageTensor(input))
let x = padToSquare(getImageTensor(input), true)
// work with 150 x 150 sized face images
if (x.shape[1] !== 150 || x.shape[2] !== 150) {
x = tf.image.resizeBilinear(x, [150, 150])
......
......@@ -3,23 +3,6 @@ import * as tf from '@tensorflow/tfjs-core';
import { NetInput } from './NetInput';
import { TNetInput } from './types';
export function padToSquare(imgTensor: tf.Tensor4D): tf.Tensor4D {
return tf.tidy(() => {
const [_, height, width] = imgTensor.shape
if (height === width) {
return imgTensor
}
if (height > width) {
const pad = tf.fill([1, height, height - width, 3], 0) as tf.Tensor4D
return tf.concat([imgTensor, pad], 2)
}
const pad = tf.fill([1, width - height, width, 3], 0) as tf.Tensor4D
return tf.concat([imgTensor, pad], 1)
})
}
export function getImageTensor(input: tf.Tensor | NetInput | TNetInput): tf.Tensor4D {
return tf.tidy(() => {
if (input instanceof tf.Tensor) {
......
import * as tf from '@tensorflow/tfjs-core';
import { euclideanDistance } from './euclideanDistance';
import { faceDetectionNet } from './faceDetectionNet';
import { faceRecognitionNet } from './faceRecognitionNet';
import { NetInput } from './NetInput';
import * as tf from '@tensorflow/tfjs-core';
import { padToSquare } from './padToSquare';
export {
euclideanDistance,
faceDetectionNet,
faceRecognitionNet,
NetInput,
tf
tf,
padToSquare
}
export * from './extractFaces'
......
import * as tf from '@tensorflow/tfjs-core';
/**
* Pads the smaller dimension of an image tensor with zeros, such that width === height.
*
* @param imgTensor The image tensor.
* @param isCenterImage (optional, default: false) If true, add padding on both sides of the image, such that the image
* @returns The padded tensor with width === height.
*/
export function padToSquare(
imgTensor: tf.Tensor4D,
isCenterImage: boolean = false
): tf.Tensor4D {
return tf.tidy(() => {
const [height, width] = imgTensor.shape.slice(1)
if (height === width) {
return imgTensor
}
const paddingAmount = Math.floor(Math.abs(height - width) * (isCenterImage ? 0.5 : 1))
const paddingAxis = height > width ? 2 : 1
const paddingTensorShape = imgTensor.shape.slice() as [number, number, number, number]
paddingTensorShape[paddingAxis] = paddingAmount
const tensorsToStack = (isCenterImage ? [tf.fill(paddingTensorShape, 0)] : [])
.concat([imgTensor, tf.fill(paddingTensorShape, 0)]) as tf.Tensor4D[]
return tf.concat(tensorsToStack, paddingAxis)
})
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment