update tfjs

pull/356/head
Vladimir Mandic 2022-08-24 08:10:36 -04:00
parent db74ab4c97
commit d5eb5e40ff
15 changed files with 1043 additions and 1033 deletions

View File

@ -11,6 +11,8 @@
### **HEAD -> main** 2022/08/21 mandic00@live.com
- expand type safety
- full eslint rule rewrite
### **2.9.4** 2022/08/20 mandic00@live.com

View File

@ -11,7 +11,7 @@ import * as H from '../../dist/human.esm.js'; // equivalent of @vladmandic/Human
const humanConfig: Partial<H.Config> = { // user configuration for human, used to fine-tune behavior
// backend: 'wasm' as const,
// wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.18.0/dist/',
// wasmPath: 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@3.20.0/dist/',
// cacheSensitivity: 0,
async: false,
modelBasePath: '../../models',

View File

@ -63,23 +63,23 @@
"devDependencies": {
"@html-eslint/eslint-plugin": "^0.13.2",
"@html-eslint/parser": "^0.13.2",
"@microsoft/api-extractor": "^7.29.3",
"@tensorflow/tfjs": "^3.19.0",
"@tensorflow/tfjs-backend-cpu": "^3.19.0",
"@tensorflow/tfjs-backend-wasm": "^3.19.0",
"@tensorflow/tfjs-backend-webgl": "^3.19.0",
"@microsoft/api-extractor": "^7.29.5",
"@tensorflow/tfjs": "^3.20.0",
"@tensorflow/tfjs-backend-cpu": "^3.20.0",
"@tensorflow/tfjs-backend-wasm": "^3.20.0",
"@tensorflow/tfjs-backend-webgl": "^3.20.0",
"@tensorflow/tfjs-backend-webgpu": "0.0.1-alpha.12",
"@tensorflow/tfjs-converter": "^3.19.0",
"@tensorflow/tfjs-core": "^3.19.0",
"@tensorflow/tfjs-data": "^3.19.0",
"@tensorflow/tfjs-layers": "^3.19.0",
"@tensorflow/tfjs-node": "^3.19.0",
"@tensorflow/tfjs-node-gpu": "^3.19.0",
"@tensorflow/tfjs-converter": "^3.20.0",
"@tensorflow/tfjs-core": "^3.20.0",
"@tensorflow/tfjs-data": "^3.20.0",
"@tensorflow/tfjs-layers": "^3.20.0",
"@tensorflow/tfjs-node": "^3.20.0",
"@tensorflow/tfjs-node-gpu": "^3.20.0",
"@tensorflow/tfjs-tflite": "0.0.1-alpha.8",
"@types/node": "^18.7.8",
"@types/node": "^18.7.13",
"@types/offscreencanvas": "^2019.7.0",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
"@vladmandic/build": "^0.7.10",
"@vladmandic/pilogger": "^0.4.6",
"@vladmandic/tfjs": "github:vladmandic/tfjs",

View File

@ -61,7 +61,7 @@ export async function load(config: Config): Promise<[GraphModel | null, GraphMod
function prepareImage(input: Tensor, size: number): Tensor {
const t: Record<string, Tensor> = {};
if (!input.shape || !input.shape[1] || !input.shape[2]) return input;
if (!input?.shape?.[1] || !input?.shape?.[2]) return input;
let final: Tensor;
if (cropBox) {
t.cropped = tf.image.cropAndResize(input, [cropBox], [0], [input.shape[1], input.shape[2]]); // if we have cached box use it to crop input

View File

@ -124,7 +124,7 @@ function parseMultiPose(res, config, image) {
}
export async function predict(input: Tensor, config: Config): Promise<BodyResult[]> {
if (!model || !model.inputs[0].shape) return []; // something is wrong with the model
if (!model?.inputs?.[0].shape) return []; // something is wrong with the model
if (!config.skipAllowed) cache.boxes.length = 0; // allowed to use cache or not
skipped++; // increment skip frames
const skipTime = (config.body.skipTime || 0) > (now() - cache.last);

View File

@ -75,7 +75,7 @@ export function jitter(keypoints: BodyKeypoint[]): BodyKeypoint[] {
export function padInput(input: Tensor, inputSize: number): Tensor {
const t: Record<string, Tensor> = {};
if (!input.shape || !input.shape[1] || !input.shape[2]) return input;
if (!input?.shape?.[1] || !input?.shape?.[2]) return input;
cache.padding = [
[0, 0], // dont touch batch
[input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], // height before&after

View File

@ -61,7 +61,7 @@ export function canvas(input: AnyCanvas | HTMLImageElement | HTMLVideoElement, o
/** meta-function that performs draw for: canvas, face, body, hand */
export async function all(inCanvas: AnyCanvas, result: Result, drawOptions?: Partial<DrawOptions>) {
if (!result || !result.performance || !result || !inCanvas) return null;
if (!result?.performance || !inCanvas) return null;
const timeStamp = now();
const localOptions = mergeDeep(options, drawOptions);
const promise = Promise.all([

View File

@ -79,7 +79,7 @@ export const iris = (res: FaceResult[]): GestureResult[] => {
if (!res) return [];
const gestures: { iris: number, gesture: IrisGesture }[] = [];
for (let i = 0; i < res.length; i++) {
if (!res[i].annotations || !res[i].annotations.leftEyeIris || !res[i].annotations.leftEyeIris[0] || !res[i].annotations.rightEyeIris || !res[i].annotations.rightEyeIris[0]) continue;
if (!res[i].annotations?.leftEyeIris?.[0] || !res[i].annotations?.rightEyeIris?.[0]) continue;
const sizeXLeft = res[i].annotations.leftEyeIris[3][0] - res[i].annotations.leftEyeIris[1][0];
const sizeYLeft = res[i].annotations.leftEyeIris[4][1] - res[i].annotations.leftEyeIris[2][1];
const areaLeft = Math.abs(sizeXLeft * sizeYLeft);

View File

@ -158,7 +158,7 @@ export async function process(input: Input, config: Config, getTensor: boolean =
if (config.filter.enabled && env.webgl.supported) {
if (!fx) fx = env.browser ? new fxImage.GLImageFilter() : null; // && (typeof document !== 'undefined')
env.filter = !!fx;
if (!fx || !fx.add) {
if (!fx?.add) {
if (config.debug) log('input process error: cannot initialize filters');
env.webgl.supported = false;
config.filter.enabled = false;

View File

@ -45,7 +45,7 @@ function extensions(): void {
export function register(instance: Human): void {
// force backend reload if gl context is not valid
if (instance.config.backend !== 'humangl') return;
if ((config.name in tf.engine().registry) && (!config.gl || !config.gl.getParameter(config.gl.VERSION))) {
if ((config.name in tf.engine().registry) && !config?.gl?.getParameter(config.gl.VERSION)) {
log('error: humangl backend invalid context');
models.reset(instance);
/*

View File

@ -19,7 +19,7 @@ export interface ProfileData {
}
export function run(modelName: string, profileData: ProfileData): void { // profileData is tfjs internal type
if (!profileData || !profileData.kernels) return;
if (!profileData?.kernels) return;
const maxDetected = 5;
const time = (profileData.kernels)
.filter((a) => a.kernelTimeMs > 0)

View File

@ -112,7 +112,7 @@ export async function runCompile(allModels: Models) {
if (!tf.env().flagRegistry.ENGINE_COMPILE_ONLY) return; // tfjs does not support compile-only inference
const backendType = tf.getBackend();
const webGLBackend = tf.backend();
if ((backendType !== 'webgl' && backendType !== 'humangl') || (!webGLBackend || !webGLBackend.checkCompileCompletion)) {
if ((backendType !== 'webgl' && backendType !== 'humangl') || !webGLBackend?.checkCompileCompletion) {
// log('compile pass: skip');
return;
}

View File

@ -1,39 +1,39 @@
2022-08-21 15:21:09 DATA:  Build {"name":"@vladmandic/human","version":"2.9.4"}
2022-08-21 15:21:09 INFO:  Application: {"name":"@vladmandic/human","version":"2.9.4"}
2022-08-21 15:21:09 INFO:  Environment: {"profile":"production","config":".build.json","package":"package.json","tsconfig":true,"eslintrc":true,"git":true}
2022-08-21 15:21:09 INFO:  Toolchain: {"build":"0.7.10","esbuild":"0.15.5","typescript":"4.7.4","typedoc":"0.23.10","eslint":"8.22.0"}
2022-08-21 15:21:09 INFO:  Build: {"profile":"production","steps":["clean","compile","typings","typedoc","lint","changelog"]}
2022-08-21 15:21:09 STATE: Clean: {"locations":["dist/*","types/lib/*","typedoc/*"]}
2022-08-21 15:21:09 STATE: Compile: {"name":"tfjs/nodejs/cpu","format":"cjs","platform":"node","input":"tfjs/tf-node.ts","output":"dist/tfjs.esm.js","files":1,"inputBytes":159,"outputBytes":608}
2022-08-21 15:21:09 STATE: Compile: {"name":"human/nodejs/cpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node.js","files":75,"inputBytes":653284,"outputBytes":306632}
2022-08-21 15:21:09 STATE: Compile: {"name":"tfjs/nodejs/gpu","format":"cjs","platform":"node","input":"tfjs/tf-node-gpu.ts","output":"dist/tfjs.esm.js","files":1,"inputBytes":167,"outputBytes":612}
2022-08-21 15:21:09 STATE: Compile: {"name":"human/nodejs/gpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-gpu.js","files":75,"inputBytes":653288,"outputBytes":306636}
2022-08-21 15:21:09 STATE: Compile: {"name":"tfjs/nodejs/wasm","format":"cjs","platform":"node","input":"tfjs/tf-node-wasm.ts","output":"dist/tfjs.esm.js","files":1,"inputBytes":206,"outputBytes":664}
2022-08-21 15:21:09 STATE: Compile: {"name":"human/nodejs/wasm","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-wasm.js","files":75,"inputBytes":653340,"outputBytes":306686}
2022-08-21 15:21:09 STATE: Compile: {"name":"tfjs/browser/version","format":"esm","platform":"browser","input":"tfjs/tf-version.ts","output":"dist/tfjs.version.js","files":1,"inputBytes":1125,"outputBytes":358}
2022-08-21 15:21:09 STATE: Compile: {"name":"tfjs/browser/esm/nobundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1088,"outputBytes":583}
2022-08-21 15:21:09 STATE: Compile: {"name":"human/browser/esm/nobundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm-nobundle.js","files":75,"inputBytes":653259,"outputBytes":305505}
2022-08-21 15:21:09 STATE: Compile: {"name":"tfjs/browser/esm/custom","format":"esm","platform":"browser","input":"tfjs/tf-custom.ts","output":"dist/tfjs.esm.js","files":11,"inputBytes":1344,"outputBytes":2787569}
2022-08-21 15:21:09 STATE: Compile: {"name":"human/browser/iife/bundle","format":"iife","platform":"browser","input":"src/human.ts","output":"dist/human.js","files":75,"inputBytes":3440245,"outputBytes":1668404}
2022-08-21 15:21:09 STATE: Compile: {"name":"human/browser/esm/bundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm.js","files":75,"inputBytes":3440245,"outputBytes":3071598}
2022-08-21 15:21:14 STATE: Typings: {"input":"src/human.ts","output":"types/lib","files":30}
2022-08-21 15:21:16 STATE: TypeDoc: {"input":"src/human.ts","output":"typedoc","objects":77,"generated":true}
2022-08-21 15:21:16 STATE: Compile: {"name":"demo/typescript","format":"esm","platform":"browser","input":"demo/typescript/index.ts","output":"demo/typescript/index.js","files":1,"inputBytes":6714,"outputBytes":3134}
2022-08-21 15:21:16 STATE: Compile: {"name":"demo/faceid","format":"esm","platform":"browser","input":"demo/faceid/index.ts","output":"demo/faceid/index.js","files":2,"inputBytes":15501,"outputBytes":7733}
2022-08-21 15:21:27 STATE: Lint: {"locations":["*.json","src/**/*.ts","test/**/*.js","demo/**/*.js"],"files":111,"errors":0,"warnings":0}
2022-08-21 15:21:27 STATE: ChangeLog: {"repository":"https://github.com/vladmandic/human","branch":"main","output":"CHANGELOG.md"}
2022-08-21 15:21:27 STATE: Copy: {"input":"tfjs/tfjs.esm.d.ts"}
2022-08-21 15:21:27 INFO:  Done...
2022-08-21 15:21:27 STATE: API-Extractor: {"succeeeded":true,"errors":0,"warnings":198}
2022-08-21 15:21:27 STATE: Copy: {"input":"types/human.d.ts"}
2022-08-21 15:21:27 INFO:  Analyze models: {"folders":8,"result":"models/models.json"}
2022-08-21 15:21:27 STATE: Models {"folder":"./models","models":13}
2022-08-21 15:21:27 STATE: Models {"folder":"../human-models/models","models":42}
2022-08-21 15:21:27 STATE: Models {"folder":"../blazepose/model/","models":4}
2022-08-21 15:21:27 STATE: Models {"folder":"../anti-spoofing/model","models":1}
2022-08-21 15:21:27 STATE: Models {"folder":"../efficientpose/models","models":3}
2022-08-21 15:21:27 STATE: Models {"folder":"../insightface/models","models":5}
2022-08-21 15:21:27 STATE: Models {"folder":"../movenet/models","models":3}
2022-08-21 15:21:27 STATE: Models {"folder":"../nanodet/models","models":4}
2022-08-21 15:21:28 STATE: Models: {"count":57,"totalSize":383017442}
2022-08-21 15:21:28 INFO:  Human Build complete... {"logFile":"test/build.log"}
2022-08-24 08:07:27 DATA:  Build {"name":"@vladmandic/human","version":"2.9.4"}
2022-08-24 08:07:27 INFO:  Application: {"name":"@vladmandic/human","version":"2.9.4"}
2022-08-24 08:07:27 INFO:  Environment: {"profile":"production","config":".build.json","package":"package.json","tsconfig":true,"eslintrc":true,"git":true}
2022-08-24 08:07:27 INFO:  Toolchain: {"build":"0.7.10","esbuild":"0.15.5","typescript":"4.7.4","typedoc":"0.23.10","eslint":"8.22.0"}
2022-08-24 08:07:27 INFO:  Build: {"profile":"production","steps":["clean","compile","typings","typedoc","lint","changelog"]}
2022-08-24 08:07:27 STATE: Clean: {"locations":["dist/*","types/lib/*","typedoc/*"]}
2022-08-24 08:07:27 STATE: Compile: {"name":"tfjs/nodejs/cpu","format":"cjs","platform":"node","input":"tfjs/tf-node.ts","output":"dist/tfjs.esm.js","files":1,"inputBytes":159,"outputBytes":608}
2022-08-24 08:07:27 STATE: Compile: {"name":"human/nodejs/cpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node.js","files":75,"inputBytes":653111,"outputBytes":306819}
2022-08-24 08:07:27 STATE: Compile: {"name":"tfjs/nodejs/gpu","format":"cjs","platform":"node","input":"tfjs/tf-node-gpu.ts","output":"dist/tfjs.esm.js","files":1,"inputBytes":167,"outputBytes":612}
2022-08-24 08:07:27 STATE: Compile: {"name":"human/nodejs/gpu","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-gpu.js","files":75,"inputBytes":653115,"outputBytes":306823}
2022-08-24 08:07:27 STATE: Compile: {"name":"tfjs/nodejs/wasm","format":"cjs","platform":"node","input":"tfjs/tf-node-wasm.ts","output":"dist/tfjs.esm.js","files":1,"inputBytes":206,"outputBytes":664}
2022-08-24 08:07:27 STATE: Compile: {"name":"human/nodejs/wasm","format":"cjs","platform":"node","input":"src/human.ts","output":"dist/human.node-wasm.js","files":75,"inputBytes":653167,"outputBytes":306873}
2022-08-24 08:07:27 STATE: Compile: {"name":"tfjs/browser/version","format":"esm","platform":"browser","input":"tfjs/tf-version.ts","output":"dist/tfjs.version.js","files":1,"inputBytes":1125,"outputBytes":358}
2022-08-24 08:07:27 STATE: Compile: {"name":"tfjs/browser/esm/nobundle","format":"esm","platform":"browser","input":"tfjs/tf-browser.ts","output":"dist/tfjs.esm.js","files":2,"inputBytes":1088,"outputBytes":583}
2022-08-24 08:07:27 STATE: Compile: {"name":"human/browser/esm/nobundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm-nobundle.js","files":75,"inputBytes":653086,"outputBytes":305692}
2022-08-24 08:07:28 STATE: Compile: {"name":"tfjs/browser/esm/custom","format":"esm","platform":"browser","input":"tfjs/tf-custom.ts","output":"dist/tfjs.esm.js","files":11,"inputBytes":1344,"outputBytes":2879073}
2022-08-24 08:07:28 STATE: Compile: {"name":"human/browser/iife/bundle","format":"iife","platform":"browser","input":"src/human.ts","output":"dist/human.js","files":75,"inputBytes":3531576,"outputBytes":1706402}
2022-08-24 08:07:28 STATE: Compile: {"name":"human/browser/esm/bundle","format":"esm","platform":"browser","input":"src/human.ts","output":"dist/human.esm.js","files":75,"inputBytes":3531576,"outputBytes":3154419}
2022-08-24 08:07:33 STATE: Typings: {"input":"src/human.ts","output":"types/lib","files":30}
2022-08-24 08:07:35 STATE: TypeDoc: {"input":"src/human.ts","output":"typedoc","objects":77,"generated":true}
2022-08-24 08:07:35 STATE: Compile: {"name":"demo/typescript","format":"esm","platform":"browser","input":"demo/typescript/index.ts","output":"demo/typescript/index.js","files":1,"inputBytes":6714,"outputBytes":3134}
2022-08-24 08:07:35 STATE: Compile: {"name":"demo/faceid","format":"esm","platform":"browser","input":"demo/faceid/index.ts","output":"demo/faceid/index.js","files":2,"inputBytes":15501,"outputBytes":7733}
2022-08-24 08:07:46 STATE: Lint: {"locations":["*.json","src/**/*.ts","test/**/*.js","demo/**/*.js"],"files":111,"errors":0,"warnings":0}
2022-08-24 08:07:47 STATE: ChangeLog: {"repository":"https://github.com/vladmandic/human","branch":"main","output":"CHANGELOG.md"}
2022-08-24 08:07:47 STATE: Copy: {"input":"tfjs/tfjs.esm.d.ts"}
2022-08-24 08:07:47 INFO:  Done...
2022-08-24 08:07:47 STATE: API-Extractor: {"succeeeded":true,"errors":0,"warnings":198}
2022-08-24 08:07:47 STATE: Copy: {"input":"types/human.d.ts"}
2022-08-24 08:07:47 INFO:  Analyze models: {"folders":8,"result":"models/models.json"}
2022-08-24 08:07:47 STATE: Models {"folder":"./models","models":13}
2022-08-24 08:07:47 STATE: Models {"folder":"../human-models/models","models":42}
2022-08-24 08:07:47 STATE: Models {"folder":"../blazepose/model/","models":4}
2022-08-24 08:07:47 STATE: Models {"folder":"../anti-spoofing/model","models":1}
2022-08-24 08:07:47 STATE: Models {"folder":"../efficientpose/models","models":3}
2022-08-24 08:07:47 STATE: Models {"folder":"../insightface/models","models":5}
2022-08-24 08:07:47 STATE: Models {"folder":"../movenet/models","models":3}
2022-08-24 08:07:47 STATE: Models {"folder":"../nanodet/models","models":4}
2022-08-24 08:07:48 STATE: Models: {"count":57,"totalSize":383017442}
2022-08-24 08:07:48 INFO:  Human Build complete... {"logFile":"test/build.log"}

View File

@ -296,6 +296,8 @@ async function test(Human, inputConfig) {
const loaded = models.filter((model) => model.loaded);
if (models.length === 23 && loaded.length === 12) log('state', 'passed: models loaded', models.length, loaded.length, models);
else log('error', 'failed: models loaded', models.length, loaded.length, models);
log('info', 'memory:', { memory: human.tf.memory() });
log('info', 'state:', { state: human.tf.engine().state });
// increase defaults
config.face = { detector: { maxDetected: 20 } };

File diff suppressed because it is too large Load Diff