added humangl custom backend

pull/70/head
Vladimir Mandic 2021-01-13 09:35:31 -05:00
parent 807343a518
commit e4324e07ab
24 changed files with 8737 additions and 8690 deletions

View File

@ -3,10 +3,11 @@ import draw from './draw.js';
import Menu from './menu.js';
import GLBench from './gl-bench.js';
const userConfig = {}; // add any user configuration overrides
const userConfig = { backend: 'humangl' }; // add any user configuration overrides
/*
const userConfig = {
backend: 'humangl',
face: { enabled: false, iris: { enabled: false } },
body: { enabled: false },
hand: { enabled: false },

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{
"inputs": {
"dist/human.esm.js": {
"bytes": 1906494,
"bytes": 1357448,
"imports": []
},
"demo/draw.js": {
@ -17,7 +17,7 @@
"imports": []
},
"demo/browser.js": {
"bytes": 25549,
"bytes": 25591,
"imports": [
{
"path": "dist/human.esm.js"
@ -38,29 +38,29 @@
"dist/demo-browser-index.js.map": {
"imports": [],
"inputs": {},
"bytes": 2027240
"bytes": 2032322
},
"dist/demo-browser-index.js": {
"imports": [],
"exports": [],
"inputs": {
"dist/human.esm.js": {
"bytesInOutput": 1899123
"bytesInOutput": 1348914
},
"demo/draw.js": {
"bytesInOutput": 7736
"bytesInOutput": 6175
},
"demo/menu.js": {
"bytesInOutput": 11792
"bytesInOutput": 10696
},
"demo/gl-bench.js": {
"bytesInOutput": 7367
"bytesInOutput": 6759
},
"demo/browser.js": {
"bytesInOutput": 19492
"bytesInOutput": 16832
}
},
"bytes": 1952895
"bytes": 1396761
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2754
dist/human.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

111
dist/human.esm.json vendored
View File

@ -5,12 +5,15 @@
"imports": []
},
"dist/tfjs.esm.js": {
"bytes": 1592080,
"bytes": 1082102,
"imports": []
},
"src/tfjs/backend.js": {
"bytes": 1376,
"bytes": 2171,
"imports": [
{
"path": "src/log.js"
},
{
"path": "dist/tfjs.esm.js"
}
@ -362,7 +365,7 @@
"imports": []
},
"src/human.js": {
"bytes": 18179,
"bytes": 18229,
"imports": [
{
"path": "src/log.js"
@ -419,7 +422,7 @@
"dist/human.esm.js.map": {
"imports": [],
"inputs": {},
"bytes": 1931767
"bytes": 1936405
},
"dist/human.esm.js": {
"imports": [],
@ -428,121 +431,121 @@
],
"inputs": {
"src/blazeface/blazeface.js": {
"bytesInOutput": 5039
"bytesInOutput": 2915
},
"src/blazeface/box.js": {
"bytesInOutput": 1567
"bytesInOutput": 987
},
"src/blazeface/util.js": {
"bytesInOutput": 2418
"bytesInOutput": 1197
},
"src/blazeface/coords.js": {
"bytesInOutput": 30718
"bytesInOutput": 30534
},
"src/blazeface/facepipeline.js": {
"bytesInOutput": 9386
"bytesInOutput": 5598
},
"src/blazeface/facemesh.js": {
"bytesInOutput": 2322
"bytesInOutput": 1518
},
"src/profile.js": {
"bytesInOutput": 851
"bytesInOutput": 637
},
"src/age/age.js": {
"bytesInOutput": 1186
"bytesInOutput": 813
},
"src/gender/gender.js": {
"bytesInOutput": 1914
"bytesInOutput": 1283
},
"src/emotion/emotion.js": {
"bytesInOutput": 1813
"bytesInOutput": 1247
},
"src/embedding/embedding.js": {
"bytesInOutput": 1323
"bytesInOutput": 870
},
"src/posenet/modelBase.js": {
"bytesInOutput": 1055
"bytesInOutput": 679
},
"src/posenet/heapSort.js": {
"bytesInOutput": 1144
"bytesInOutput": 1048
},
"src/posenet/buildParts.js": {
"bytesInOutput": 1287
"bytesInOutput": 529
},
"src/posenet/keypoints.js": {
"bytesInOutput": 1813
"bytesInOutput": 1638
},
"src/posenet/vectors.js": {
"bytesInOutput": 1055
},
"src/posenet/decoders.js": {
"bytesInOutput": 1709
},
"src/posenet/decodePose.js": {
"bytesInOutput": 4098
},
"src/posenet/decodeMultiple.js": {
"bytesInOutput": 1643
},
"src/posenet/util.js": {
"bytesInOutput": 1892
},
"src/posenet/modelPoseNet.js": {
"bytesInOutput": 1997
},
"src/posenet/posenet.js": {
"bytesInOutput": 627
},
"src/posenet/decoders.js": {
"bytesInOutput": 875
},
"src/posenet/decodePose.js": {
"bytesInOutput": 1482
},
"src/posenet/decodeMultiple.js": {
"bytesInOutput": 704
},
"src/posenet/util.js": {
"bytesInOutput": 1065
},
"src/posenet/modelPoseNet.js": {
"bytesInOutput": 1167
},
"src/posenet/posenet.js": {
"bytesInOutput": 401
},
"src/handpose/handdetector.js": {
"bytesInOutput": 2747
"bytesInOutput": 1704
},
"src/handpose/handpipeline.js": {
"bytesInOutput": 4484
"bytesInOutput": 2485
},
"src/handpose/anchors.js": {
"bytesInOutput": 127037
"bytesInOutput": 127006
},
"src/handpose/handpose.js": {
"bytesInOutput": 2023
"bytesInOutput": 1331
},
"src/gesture/gesture.js": {
"bytesInOutput": 3162
"bytesInOutput": 2424
},
"src/imagefx.js": {
"bytesInOutput": 13630
"bytesInOutput": 11004
},
"src/image.js": {
"bytesInOutput": 3652
"bytesInOutput": 2479
},
"src/log.js": {
"bytesInOutput": 266
"bytesInOutput": 252
},
"dist/tfjs.esm.js": {
"bytesInOutput": 1591040
"bytesInOutput": 1073222
},
"src/tfjs/backend.js": {
"bytesInOutput": 918
"bytesInOutput": 1205
},
"src/human.js": {
"bytesInOutput": 12177
"bytesInOutput": 9982
},
"src/handpose/box.js": {
"bytesInOutput": 1420
"bytesInOutput": 938
},
"src/handpose/util.js": {
"bytesInOutput": 1796
"bytesInOutput": 816
},
"config.js": {
"bytesInOutput": 1514
"bytesInOutput": 1460
},
"src/sample.js": {
"bytesInOutput": 55299
"bytesInOutput": 55295
},
"package.json": {
"bytesInOutput": 23
"bytesInOutput": 16
}
},
"bytes": 1906494
"bytes": 1357448
}
}
}

2754
dist/human.js vendored

File diff suppressed because one or more lines are too long

4
dist/human.js.map vendored

File diff suppressed because one or more lines are too long

111
dist/human.json vendored
View File

@ -5,12 +5,15 @@
"imports": []
},
"dist/tfjs.esm.js": {
"bytes": 1592080,
"bytes": 1082102,
"imports": []
},
"src/tfjs/backend.js": {
"bytes": 1376,
"bytes": 2171,
"imports": [
{
"path": "src/log.js"
},
{
"path": "dist/tfjs.esm.js"
}
@ -362,7 +365,7 @@
"imports": []
},
"src/human.js": {
"bytes": 18179,
"bytes": 18229,
"imports": [
{
"path": "src/log.js"
@ -419,128 +422,128 @@
"dist/human.js.map": {
"imports": [],
"inputs": {},
"bytes": 1931784
"bytes": 1936422
},
"dist/human.js": {
"imports": [],
"exports": [],
"inputs": {
"src/blazeface/blazeface.js": {
"bytesInOutput": 5039
"bytesInOutput": 2915
},
"src/blazeface/box.js": {
"bytesInOutput": 1567
"bytesInOutput": 987
},
"src/blazeface/util.js": {
"bytesInOutput": 2418
"bytesInOutput": 1197
},
"src/blazeface/coords.js": {
"bytesInOutput": 30718
"bytesInOutput": 30534
},
"src/blazeface/facepipeline.js": {
"bytesInOutput": 9386
"bytesInOutput": 5598
},
"src/blazeface/facemesh.js": {
"bytesInOutput": 2322
"bytesInOutput": 1518
},
"src/profile.js": {
"bytesInOutput": 851
"bytesInOutput": 637
},
"src/age/age.js": {
"bytesInOutput": 1186
"bytesInOutput": 813
},
"src/gender/gender.js": {
"bytesInOutput": 1914
"bytesInOutput": 1283
},
"src/emotion/emotion.js": {
"bytesInOutput": 1813
"bytesInOutput": 1247
},
"src/embedding/embedding.js": {
"bytesInOutput": 1323
"bytesInOutput": 870
},
"src/posenet/modelBase.js": {
"bytesInOutput": 1055
"bytesInOutput": 679
},
"src/posenet/heapSort.js": {
"bytesInOutput": 1144
"bytesInOutput": 1048
},
"src/posenet/buildParts.js": {
"bytesInOutput": 1287
"bytesInOutput": 529
},
"src/posenet/keypoints.js": {
"bytesInOutput": 1813
"bytesInOutput": 1638
},
"src/posenet/vectors.js": {
"bytesInOutput": 1055
},
"src/posenet/decoders.js": {
"bytesInOutput": 1709
},
"src/posenet/decodePose.js": {
"bytesInOutput": 4098
},
"src/posenet/decodeMultiple.js": {
"bytesInOutput": 1643
},
"src/posenet/util.js": {
"bytesInOutput": 1892
},
"src/posenet/modelPoseNet.js": {
"bytesInOutput": 1997
},
"src/posenet/posenet.js": {
"bytesInOutput": 627
},
"src/posenet/decoders.js": {
"bytesInOutput": 875
},
"src/posenet/decodePose.js": {
"bytesInOutput": 1482
},
"src/posenet/decodeMultiple.js": {
"bytesInOutput": 704
},
"src/posenet/util.js": {
"bytesInOutput": 1065
},
"src/posenet/modelPoseNet.js": {
"bytesInOutput": 1167
},
"src/posenet/posenet.js": {
"bytesInOutput": 401
},
"src/handpose/handdetector.js": {
"bytesInOutput": 2747
"bytesInOutput": 1704
},
"src/handpose/handpipeline.js": {
"bytesInOutput": 4484
"bytesInOutput": 2485
},
"src/handpose/anchors.js": {
"bytesInOutput": 127037
"bytesInOutput": 127006
},
"src/handpose/handpose.js": {
"bytesInOutput": 2023
"bytesInOutput": 1331
},
"src/gesture/gesture.js": {
"bytesInOutput": 3162
"bytesInOutput": 2424
},
"src/imagefx.js": {
"bytesInOutput": 13630
"bytesInOutput": 11004
},
"src/image.js": {
"bytesInOutput": 3652
"bytesInOutput": 2479
},
"src/human.js": {
"bytesInOutput": 12242
"bytesInOutput": 10018
},
"src/log.js": {
"bytesInOutput": 266
"bytesInOutput": 252
},
"dist/tfjs.esm.js": {
"bytesInOutput": 1591040
"bytesInOutput": 1073222
},
"src/tfjs/backend.js": {
"bytesInOutput": 918
"bytesInOutput": 1205
},
"src/handpose/box.js": {
"bytesInOutput": 1420
"bytesInOutput": 938
},
"src/handpose/util.js": {
"bytesInOutput": 1796
"bytesInOutput": 816
},
"config.js": {
"bytesInOutput": 1514
"bytesInOutput": 1460
},
"src/sample.js": {
"bytesInOutput": 55299
"bytesInOutput": 55295
},
"package.json": {
"bytesInOutput": 23
"bytesInOutput": 16
}
},
"bytes": 1906572
"bytes": 1357490
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

12
dist/human.node.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

19
dist/human.node.json vendored
View File

@ -9,8 +9,11 @@
"imports": []
},
"src/tfjs/backend.js": {
"bytes": 1376,
"bytes": 2171,
"imports": [
{
"path": "src/log.js"
},
{
"path": "dist/tfjs.esm.js"
}
@ -358,11 +361,11 @@
"imports": []
},
"package.json": {
"bytes": 2325,
"bytes": 2336,
"imports": []
},
"src/human.js": {
"bytes": 18179,
"bytes": 18229,
"imports": [
{
"path": "src/log.js"
@ -419,7 +422,7 @@
"dist/human.node-gpu.js.map": {
"imports": [],
"inputs": {},
"bytes": 708268
"bytes": 709451
},
"dist/human.node-gpu.js": {
"imports": [],
@ -492,7 +495,7 @@
"bytesInOutput": 1180
},
"src/posenet/posenet.js": {
"bytesInOutput": 379
"bytesInOutput": 385
},
"src/handpose/handdetector.js": {
"bytesInOutput": 1844
@ -516,13 +519,13 @@
"bytesInOutput": 2478
},
"src/human.js": {
"bytesInOutput": 10086
"bytesInOutput": 10118
},
"src/log.js": {
"bytesInOutput": 251
},
"src/tfjs/backend.js": {
"bytesInOutput": 844
"bytesInOutput": 1304
},
"src/handpose/box.js": {
"bytesInOutput": 958
@ -540,7 +543,7 @@
"bytesInOutput": 16
}
},
"bytes": 277817
"bytes": 278315
}
}
}

2736
dist/tfjs.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

5960
dist/tfjs.esm.json vendored

File diff suppressed because it is too large Load Diff

9
package-lock.json generated
View File

@ -553,6 +553,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
@ -1280,7 +1281,8 @@
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"functional-red-black-tree": {
"version": "1.0.1",
@ -1351,6 +1353,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.0.2.tgz",
"integrity": "sha512-aeX0vrFm21ILl3+JpFFRNe9aUvp6VFZb2/CTbgLb8j75kOhvoNYjt9d8KA/tJG4gSo8nzEDedRl0h7vDmBYRVg==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
@ -1405,6 +1408,7 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"requires": {
"function-bind": "^1.1.1"
}
@ -1418,7 +1422,8 @@
"has-symbols": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
"integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg=="
"integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==",
"dev": true
},
"has-unicode": {
"version": "2.0.1",

View File

@ -182,12 +182,12 @@ class Human {
if (!simd) log('warning: wasm simd support is not enabled');
}
if (this.config.backend === 'humangl') {
log('registering humangl backend');
backend.register();
if (this.config.backend === 'humangl') backend.register();
try {
await tf.setBackend(this.config.backend);
} catch (err) {
log('error: cannot set backend:', this.config.backend, err);
}
await tf.setBackend(this.config.backend);
tf.enableProdMode();
/* debug mode is really too mcuh
tf.enableDebugMode();

View File

@ -1,9 +1,11 @@
import { log } from '../log.js';
import * as tf from '../../dist/tfjs.esm.js';
export const config = {
name: 'humangl',
priority: 99,
canvas: null,
gl: null,
width: 1024,
height: 1024,
webGLattr: { // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.2
@ -20,21 +22,51 @@ export const config = {
export function register() {
if (!tf.findBackend(config.name)) {
// @ts-ignore
config.canvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(config.width, config.height) : document.createElement('canvas');
// @ts-ignore
const gl = config.canvas.getContext('webgl2', config.webGLattr);
tf.setWebGLContext(2, gl);
const ctx = new tf.GPGPUContext(gl);
tf.registerBackend(config.name, () => new tf.MathBackendWebGL(ctx), config.priority);
const kernels = tf.getKernelsForBackend('webgl');
kernels.forEach((kernelConfig) => {
const newKernelConfig = { ...kernelConfig, backendName: config.name };
tf.registerKernel(newKernelConfig);
});
tf.ENV.set('WEBGL_VERSION', 2);
tf.ENV.set('WEBGL_MAX_TEXTURE_SIZE', gl.getParameter(gl.MAX_TEXTURE_SIZE));
tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true);
tf.ENV.set('WEBGL_PACK_DEPTHWISECONV', true);
log('backend registration:', config.name);
try {
config.canvas = (typeof OffscreenCanvas !== 'undefined') ? new OffscreenCanvas(config.width, config.height) : document.createElement('canvas');
} catch (err) {
log('error: cannot create canvas:', err);
return;
}
try {
config.gl = config.canvas.getContext('webgl2', config.webGLattr);
} catch (err) {
log('error: cannot get WebGL2 context:', err);
return;
}
try {
tf.setWebGLContext(2, config.gl);
} catch (err) {
log('error: cannot set WebGL2 context:', err);
return;
}
try {
const ctx = new tf.GPGPUContext(config.gl);
tf.registerBackend(config.name, () => new tf.MathBackendWebGL(ctx), config.priority);
} catch (err) {
log('error: cannot register WebGL backend:', err);
return;
}
try {
const kernels = tf.getKernelsForBackend('webgl');
kernels.forEach((kernelConfig) => {
const newKernelConfig = { ...kernelConfig, backendName: config.name };
tf.registerKernel(newKernelConfig);
});
} catch (err) {
log('error: cannot update WebGL backend registration:', err);
return;
}
try {
tf.ENV.set('WEBGL_VERSION', 2);
tf.ENV.set('WEBGL_MAX_TEXTURE_SIZE', config.gl.getParameter(config.gl.MAX_TEXTURE_SIZE));
tf.ENV.set('WEBGL_FORCE_F16_TEXTURES', true);
tf.ENV.set('WEBGL_PACK_DEPTHWISECONV', true);
} catch (err) {
log('error: cannot set WebGL backend flags:', err);
return;
}
log('backend registered:', config.name);
}
}

2
wiki

@ -1 +1 @@
Subproject commit 0ce580ced2bdf5f2f231dfae6c3d3f90053af6f6
Subproject commit c83eeeb158f2183d963500d9a767f04851497d2f