Commit 01c3821d by Jonathan Derrough

Refactored by adding LabeledFaceDescriptors.fromJSON() & .fromPOJO()

Added FaceMatcher.fromPOJO() Updated FaceMatcher tests and added tests for LabeledFaceDescriptors
parent 16d6f4d9
......@@ -4,4 +4,6 @@ export declare class LabeledFaceDescriptors {
constructor(label: string, descriptors: Float32Array[]);
readonly label: string;
readonly descriptors: Float32Array[];
static fromJSON(jsonString: string): LabeledFaceDescriptors;
static fromPOJO(pojo: any): LabeledFaceDescriptors;
}
......@@ -21,6 +21,15 @@ var LabeledFaceDescriptors = /** @class */ (function () {
enumerable: true,
configurable: true
});
LabeledFaceDescriptors.fromJSON = function (jsonString) {
return LabeledFaceDescriptors.fromPOJO(JSON.parse(jsonString));
};
LabeledFaceDescriptors.fromPOJO = function (pojo) {
var descriptors = pojo._descriptors.map(function (d) {
return new Float32Array(Object.keys(d).map(function (key) { return d[key]; }));
});
return new LabeledFaceDescriptors(pojo._label, descriptors);
};
return LabeledFaceDescriptors;
}());
exports.LabeledFaceDescriptors = LabeledFaceDescriptors;
......
{"version":3,"file":"LabeledFaceDescriptors.js","sourceRoot":"","sources":["../../../src/classes/LabeledFaceDescriptors.ts"],"names":[],"mappings":";;AAAA;IAIE,gCAAY,KAAa,EAAE,WAA2B;QACpD,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;SACtF;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,CAAC,IAAI,YAAY,YAAY,CAAC,EAA/B,CAA+B,CAAC,EAAE;YAC5F,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAA;SAC5G;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACjC,CAAC;IAED,sBAAW,yCAAK;aAAhB,cAA6B,OAAO,IAAI,CAAC,MAAM,CAAA,CAAC,CAAC;;;OAAA;IACjD,sBAAW,+CAAW;aAAtB,cAA2C,OAAO,IAAI,CAAC,YAAY,CAAA,CAAC,CAAC;;;OAAA;IAEvE,6BAAC;AAAD,CAAC,AApBD,IAoBC;AApBY,wDAAsB"}
\ No newline at end of file
{"version":3,"file":"LabeledFaceDescriptors.js","sourceRoot":"","sources":["../../../src/classes/LabeledFaceDescriptors.ts"],"names":[],"mappings":";;AAAA;IAIE,gCAAY,KAAa,EAAE,WAA2B;QACpD,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;SACtF;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,CAAC,IAAI,YAAY,YAAY,CAAC,EAA/B,CAA+B,CAAC,EAAE;YAC5F,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAA;SAC5G;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACjC,CAAC;IAED,sBAAW,yCAAK;aAAhB,cAA6B,OAAO,IAAI,CAAC,MAAM,CAAA,CAAC,CAAC;;;OAAA;IACjD,sBAAW,+CAAW;aAAtB,cAA2C,OAAO,IAAI,CAAC,YAAY,CAAA,CAAC,CAAC;;;OAAA;IAEvD,+BAAQ,GAAtB,UAAuB,UAAkB;QACvC,OAAO,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC;IAEa,+BAAQ,GAAtB,UAAuB,IAAS;QAC9B,IAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAC,CAAM;YAC/C,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,CAAC,GAAG,CAAC,EAAN,CAAM,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,sBAAsB,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC9D,CAAC;IAEH,6BAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,wDAAsB"}
\ No newline at end of file
......@@ -11,4 +11,5 @@ export declare class FaceMatcher {
matchDescriptor(queryDescriptor: Float32Array): FaceMatch;
findBestMatch(queryDescriptor: Float32Array): FaceMatch;
static fromJSON(jsonString: string): FaceMatcher;
static fromPOJO(pojo: any): FaceMatcher;
}
......@@ -58,15 +58,12 @@ var FaceMatcher = /** @class */ (function () {
: new FaceMatch_1.FaceMatch('unknown', bestMatch.distance);
};
FaceMatcher.fromJSON = function (jsonString) {
var poco = JSON.parse(jsonString);
var labeledDescriptors = poco._labeledDescriptors
.map(function (_a) {
var _label = _a._label, _descriptors = _a._descriptors;
return new LabeledFaceDescriptors_1.LabeledFaceDescriptors(_label, _descriptors.map(function (d) {
return new Float32Array(Object.keys(d).map(function (key) { return d[key]; }));
}));
});
return new FaceMatcher(labeledDescriptors, poco._distanceThreshold);
return FaceMatcher.fromPOJO(JSON.parse(jsonString));
};
FaceMatcher.fromPOJO = function (pojo) {
var labeledDescriptors = pojo._labeledDescriptors
.map(function (ld) { return LabeledFaceDescriptors_1.LabeledFaceDescriptors.fromPOJO(ld); });
return new FaceMatcher(labeledDescriptors, pojo._distanceThreshold);
};
return FaceMatcher;
}());
......
{"version":3,"file":"FaceMatcher.js","sourceRoot":"","sources":["../../../src/globalApi/FaceMatcher.ts"],"names":[],"mappings":";;AAAA,kDAAiD;AACjD,4EAA2E;AAC3E,0DAAyD;AAGzD;IAKE,qBACE,MAAgJ,EAChJ,iBAA+B;QAA/B,kCAAA,EAAA,uBA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AChD,IAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAA;QACvD,OAAO,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC,iBAAiB;YAChD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,qBAAS,CAAC,SAAS,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAA;IAClD,CAAC;IAEa,oBAAQ,GAAtB,UAAuB,UAAkB;QACvC,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACtD,CAAC;IAEa,oBAAQ,GAAtB,UAAuB,IAAS;QAC9B,IAAM,kBAAkB,GAAG,IAAI,CAAC,mBAAmB;aAChD,GAAG,CAAC,UAAC,EAAO,IAAK,OAAA,+CAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAnC,CAAmC,CAAC,CAAC;QACzD,OAAO,IAAI,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACtE,CAAC;IAEH,kBAAC;AAAD,CAAC,AA1ED,IA0EC;AA1EY,kCAAW"}
\ No newline at end of file
......@@ -4,4 +4,6 @@ export declare class LabeledFaceDescriptors {
constructor(label: string, descriptors: Float32Array[]);
readonly label: string;
readonly descriptors: Float32Array[];
static fromJSON(jsonString: string): LabeledFaceDescriptors;
static fromPOJO(pojo: any): LabeledFaceDescriptors;
}
......@@ -19,6 +19,15 @@ var LabeledFaceDescriptors = /** @class */ (function () {
enumerable: true,
configurable: true
});
LabeledFaceDescriptors.fromJSON = function (jsonString) {
return LabeledFaceDescriptors.fromPOJO(JSON.parse(jsonString));
};
LabeledFaceDescriptors.fromPOJO = function (pojo) {
var descriptors = pojo._descriptors.map(function (d) {
return new Float32Array(Object.keys(d).map(function (key) { return d[key]; }));
});
return new LabeledFaceDescriptors(pojo._label, descriptors);
};
return LabeledFaceDescriptors;
}());
export { LabeledFaceDescriptors };
......
{"version":3,"file":"LabeledFaceDescriptors.js","sourceRoot":"","sources":["../../../src/classes/LabeledFaceDescriptors.ts"],"names":[],"mappings":"AAAA;IAIE,gCAAY,KAAa,EAAE,WAA2B;QACpD,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;SACtF;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,CAAC,IAAI,YAAY,YAAY,CAAC,EAA/B,CAA+B,CAAC,EAAE;YAC5F,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAA;SAC5G;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACjC,CAAC;IAED,sBAAW,yCAAK;aAAhB,cAA6B,OAAO,IAAI,CAAC,MAAM,CAAA,CAAC,CAAC;;;OAAA;IACjD,sBAAW,+CAAW;aAAtB,cAA2C,OAAO,IAAI,CAAC,YAAY,CAAA,CAAC,CAAC;;;OAAA;IAEvE,6BAAC;AAAD,CAAC,AApBD,IAoBC"}
\ No newline at end of file
{"version":3,"file":"LabeledFaceDescriptors.js","sourceRoot":"","sources":["../../../src/classes/LabeledFaceDescriptors.ts"],"names":[],"mappings":"AAAA;IAIE,gCAAY,KAAa,EAAE,WAA2B;QACpD,IAAI,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;SACtF;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,CAAC,IAAI,YAAY,YAAY,CAAC,EAA/B,CAA+B,CAAC,EAAE;YAC5F,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAA;SAC5G;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACjC,CAAC;IAED,sBAAW,yCAAK;aAAhB,cAA6B,OAAO,IAAI,CAAC,MAAM,CAAA,CAAC,CAAC;;;OAAA;IACjD,sBAAW,+CAAW;aAAtB,cAA2C,OAAO,IAAI,CAAC,YAAY,CAAA,CAAC,CAAC;;;OAAA;IAEvD,+BAAQ,GAAtB,UAAuB,UAAkB;QACvC,OAAO,sBAAsB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACjE,CAAC;IAEa,+BAAQ,GAAtB,UAAuB,IAAS;QAC9B,IAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAC,CAAM;YAC/C,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,CAAC,GAAG,CAAC,EAAN,CAAM,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,sBAAsB,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC9D,CAAC;IAEH,6BAAC;AAAD,CAAC,AA/BD,IA+BC"}
\ No newline at end of file
......@@ -11,4 +11,5 @@ export declare class FaceMatcher {
matchDescriptor(queryDescriptor: Float32Array): FaceMatch;
findBestMatch(queryDescriptor: Float32Array): FaceMatch;
static fromJSON(jsonString: string): FaceMatcher;
static fromPOJO(pojo: any): FaceMatcher;
}
......@@ -56,15 +56,12 @@ var FaceMatcher = /** @class */ (function () {
: new FaceMatch('unknown', bestMatch.distance);
};
FaceMatcher.fromJSON = function (jsonString) {
var poco = JSON.parse(jsonString);
var labeledDescriptors = poco._labeledDescriptors
.map(function (_a) {
var _label = _a._label, _descriptors = _a._descriptors;
return new LabeledFaceDescriptors(_label, _descriptors.map(function (d) {
return new Float32Array(Object.keys(d).map(function (key) { return d[key]; }));
}));
});
return new FaceMatcher(labeledDescriptors, poco._distanceThreshold);
return FaceMatcher.fromPOJO(JSON.parse(jsonString));
};
FaceMatcher.fromPOJO = function (pojo) {
var labeledDescriptors = pojo._labeledDescriptors
.map(function (ld) { return LabeledFaceDescriptors.fromPOJO(ld); });
return new FaceMatcher(labeledDescriptors, pojo._distanceThreshold);
};
return FaceMatcher;
}());
......
{"version":3,"file":"FaceMatcher.js","sourceRoot":"","sources":["../../../src/globalApi/FaceMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGzD;IAKE,qBACE,MAAgJ,EAChJ,iBAA+B;QAA/B,kCAAA,EAAA,uBAA+B;QAG/B,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAA;QAE3C,IAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QAE5D,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;SAC3E;QAED,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,IAAM,iBAAiB,GAAG,cAAM,OAAA,YAAU,KAAK,EAAI,EAAnB,CAAmB,CAAA;QAEnD,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,GAAG,CAAC,UAAC,IAAI;YAC7C,IAAI,IAAI,YAAY,sBAAsB,EAAE;gBAC1C,OAAO,IAAI,CAAA;aACZ;YAED,IAAI,IAAI,YAAY,YAAY,EAAE;gBAChC,OAAO,IAAI,sBAAsB,CAAC,iBAAiB,EAAE,EAAE,CAAC,IAA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nC,CAAmC,CAAC,CAAC;QACzD,OAAO,IAAI,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACtE,CAAC;IAEH,kBAAC;AAAD,CAAC,AA1ED,IA0EC"}
\ No newline at end of file
......@@ -3468,6 +3468,15 @@
enumerable: true,
configurable: true
});
LabeledFaceDescriptors.fromJSON = function (jsonString) {
return LabeledFaceDescriptors.fromPOJO(JSON.parse(jsonString));
};
LabeledFaceDescriptors.fromPOJO = function (pojo) {
var descriptors = pojo._descriptors.map(function (d) {
return new Float32Array(Object.keys(d).map(function (key) { return d[key]; }));
});
return new LabeledFaceDescriptors(pojo._label, descriptors);
};
return LabeledFaceDescriptors;
}());
......@@ -6341,15 +6350,12 @@
: new FaceMatch('unknown', bestMatch.distance);
};
FaceMatcher.fromJSON = function (jsonString) {
var poco = JSON.parse(jsonString);
var labeledDescriptors = poco._labeledDescriptors
.map(function (_a) {
var _label = _a._label, _descriptors = _a._descriptors;
return new LabeledFaceDescriptors(_label, _descriptors.map(function (d) {
return new Float32Array(Object.keys(d).map(function (key) { return d[key]; }));
}));
});
return new FaceMatcher(labeledDescriptors, poco._distanceThreshold);
return FaceMatcher.fromPOJO(JSON.parse(jsonString));
};
FaceMatcher.fromPOJO = function (pojo) {
var labeledDescriptors = pojo._labeledDescriptors
.map(function (ld) { return LabeledFaceDescriptors.fromPOJO(ld); });
return new FaceMatcher(labeledDescriptors, pojo._distanceThreshold);
};
return FaceMatcher;
}());
......
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.
......@@ -18,4 +18,15 @@ export class LabeledFaceDescriptors {
public get label(): string { return this._label }
public get descriptors(): Float32Array[] { return this._descriptors }
public static fromJSON(jsonString: string): LabeledFaceDescriptors {
return LabeledFaceDescriptors.fromPOJO(JSON.parse(jsonString));
}
public static fromPOJO(pojo: any): LabeledFaceDescriptors {
const descriptors = pojo._descriptors.map((d: any) => {
return new Float32Array(Object.keys(d).map(key => d[key]));
});
return new LabeledFaceDescriptors(pojo._label, descriptors);
}
}
\ No newline at end of file
......@@ -68,14 +68,13 @@ export class FaceMatcher {
}
public static fromJSON(jsonString: string): FaceMatcher {
const poco: any = JSON.parse(jsonString);
const labeledDescriptors = poco._labeledDescriptors
.map(({ _label, _descriptors }: { _label: string, _descriptors: any }) => {
return new LabeledFaceDescriptors(_label, _descriptors.map((d: any) => {
return new Float32Array(Object.keys(d).map(key => d[key]));
}));
});
return new FaceMatcher(labeledDescriptors, poco._distanceThreshold);
return FaceMatcher.fromPOJO(JSON.parse(jsonString));
}
public static fromPOJO(pojo: any): FaceMatcher {
const labeledDescriptors = pojo._labeledDescriptors
.map((ld: any) => LabeledFaceDescriptors.fromPOJO(ld));
return new FaceMatcher(labeledDescriptors, pojo._distanceThreshold);
}
}
\ No newline at end of file
import { LabeledFaceDescriptors } from '../../../src';
describe('globalApi', () => {
describe('LabeledFaceDescriptors', () => {
const json = '{"_label":"foo","_descriptors":[{"0":1,"1":2,"2":3},{"0":4,"1":5,"2":6}]}';
const l1 = 'foo';
const f1 = new Float32Array([1, 2, 3]);
const f2 = new Float32Array([4, 5, 6]);
it('fromJSON()', () => {
const ld = LabeledFaceDescriptors.fromJSON(json);
expect(ld.label).toBe(l1);
expect(ld.descriptors.length).toBe(2);
expect(ld.descriptors[0]).toEqual(f1);
expect(ld.descriptors[1]).toEqual(f2);
});
it('fromPOJO()', () => {
const ld = LabeledFaceDescriptors.fromPOJO(JSON.parse(json));
expect(ld.label).toBe(l1);
expect(ld.descriptors.length).toBe(2);
expect(ld.descriptors[0]).toEqual(f1);
expect(ld.descriptors[1]).toEqual(f2);
});
it('JSON.stringify() => fromJSON()', () => {
const ld = LabeledFaceDescriptors.fromJSON(JSON.stringify(new LabeledFaceDescriptors(l1, [f1,f2])));
expect(ld.label).toBe(l1);
expect(ld.descriptors.length).toBe(2);
expect(ld.descriptors[0]).toEqual(f1);
expect(ld.descriptors[1]).toEqual(f2);
});
});
});
\ No newline at end of file
......@@ -33,7 +33,22 @@ describe('globalApi', () => {
expect(fm.labeledDescriptors[1].descriptors[1]).toEqual(f4);
});
it('toJSON() => fromJSON()', () => {
it('fromPOJO()', () => {
const fm = FaceMatcher.fromPOJO(JSON.parse(json));
expect(fm.distanceThreshold).toBe(dt);
expect(fm.labeledDescriptors.length).toBe(2);
expect(fm.labeledDescriptors[0].label).toBe(l1);
expect(fm.labeledDescriptors[0].descriptors.length).toBe(2);
expect(fm.labeledDescriptors[0].descriptors[0]).toEqual(f1);
expect(fm.labeledDescriptors[0].descriptors[1]).toEqual(f2);
expect(fm.labeledDescriptors[1].label).toBe(l2);
expect(fm.labeledDescriptors[1].descriptors.length).toBe(2);
expect(fm.labeledDescriptors[1].descriptors[0]).toEqual(f3);
expect(fm.labeledDescriptors[1].descriptors[1]).toEqual(f4);
});
it('JSON.stringify() => fromJSON()', () => {
const fm = FaceMatcher.fromJSON(JSON.stringify(new FaceMatcher(lds, dt)));
expect(fm.distanceThreshold).toBe(dt);
......
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