human/test/test-embedding.html

109 lines
4.5 KiB
HTML
Raw Normal View History

2022-09-02 14:08:21 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<title>Human Embedding Tests</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, shrink-to-fit=yes">
<style>
2022-09-02 16:22:24 +02:00
html { font-size: 10px; font-variant: small-caps; }
2022-09-02 14:08:21 +02:00
body { margin: 0; background: black; color: white; width: 100vw; }
</style>
</head>
<body>
<pre id="log" style="line-height: 150%; overflow-x: hidden; white-space: pre-wrap"></pre>
<script type="module">
2022-09-02 16:22:24 +02:00
/// import { Human } from 'https://vladmandic.github.io/human/dist/human.esm.js';
import { Human } from '../dist/human.esm.js';
2022-09-02 14:08:21 +02:00
const testConfig = {
debug: true,
async: false,
modelBasePath: 'https://vladmandic.github.io/human-models/models/',
cacheSensitivity: 0,
2022-09-02 16:22:24 +02:00
cacheModels: false,
2022-09-02 14:08:21 +02:00
warmup: 'face',
face: { iris: { enabled: false }, emotion: { enabled: false } },
body: { enabled: false },
hand: { enabled: false },
object: { enabled: false },
segmentation: { enabled: false },
gestures: { enabled: false },
};
function str(...msg) {
if (!Array.isArray(msg)) return msg;
let line = '';
for (const entry of msg) {
if (typeof entry === 'object') line += ' ' + JSON.stringify(entry, null, 0).replace(/"/g, '').replace(/,/g, ', ').replace(/:/g, ': ');
else line += ' ' + entry;
}
return line + '\n';
}
async function log(...msgs) {
document.getElementById('log').innerHTML += str(...msgs);
document.documentElement.scrollTop = document.documentElement.scrollHeight;
console.log(...msgs); // eslint-disable-line no-console
}
async function main() {
const human = new Human(testConfig);
log('human', human.version, { config: human.config });
2022-09-02 16:22:24 +02:00
// for (const backend of ['wasm', 'webgl', 'humangl', 'webgpu', 'test1', 'test2', 'test3', 'test4']) {
// for (const backend of ['webgl']) {
for (const backend of ['webgl', 'humangl', 'test1', 'test2', 'test3', 'test4']) {
human.reset();
2022-09-02 14:08:21 +02:00
if (backend === 'test1') {
human.config.backend = 'humangl';
await human.init();
2022-09-02 16:22:24 +02:00
human.tf.env().set('WEBGL_USE_SHAPES_UNIFORMS', false);
human.tf.env().set('WEBGL_EXP_CONV', false);
2022-09-02 14:08:21 +02:00
} else if (backend === 'test2') {
human.config.backend = 'humangl';
await human.init();
human.tf.env().set('WEBGL_USE_SHAPES_UNIFORMS', true);
2022-09-02 16:22:24 +02:00
human.tf.env().set('WEBGL_EXP_CONV', false);
2022-09-02 14:08:21 +02:00
} else if (backend === 'test3') {
human.config.backend = 'humangl';
await human.init();
2022-09-02 16:22:24 +02:00
human.tf.env().set('WEBGL_USE_SHAPES_UNIFORMS', false);
human.tf.env().set('WEBGL_EXP_CONV', true);
2022-09-02 14:08:21 +02:00
} else if (backend === 'test4') {
human.config.backend = 'humangl';
await human.init();
2022-09-02 16:22:24 +02:00
human.tf.env().set('WEBGL_USE_SHAPES_UNIFORMS', true);
human.tf.env().set('WEBGL_EXP_CONV', true);
2022-09-02 14:08:21 +02:00
} else {
human.config.backend = backend;
await human.init();
if (human.tf.getBackend() !== backend) {
log(backend, { desired: backend, detected: human.tf.getBackend() });
continue; // wrong backend
}
}
let res;
2022-09-02 16:22:24 +02:00
/*
2022-09-02 14:08:21 +02:00
for (const model of Object.keys(human.models)) {
if (human.models[model]) human.models[model] = null;
}
await human.load(testConfig);
2022-09-02 16:22:24 +02:00
*/
2022-09-02 14:08:21 +02:00
const ops = await human.check();
if (ops && ops.length > 0) log(backend, { backend: human.tf.getBackend(), ops });
const env = JSON.parse(JSON.stringify(human.env));
env.kernels = human.env.kernels.length;
2022-09-02 16:22:24 +02:00
log(backend, { backend: human.tf.getBackend(), env, tfjs: human.tf.env().flags });
2022-09-02 14:08:21 +02:00
for (const warmup of ['none', 'face', 'body']) {
testConfig.warmup = warmup;
res = await human.warmup(testConfig);
if (Array.isArray(res?.face?.[0]?.embedding) && (res?.face?.[0]?.embedding.length === 1024)) res.face[0].embedding.length = 10;
log(backend, { backend: human.tf.getBackend(), warmup, gender: res?.face?.[0]?.gender, genderScore: res?.face?.[0]?.genderScore, age: res?.face?.[0]?.age, embedding: res?.face?.[0]?.embedding });
}
}
}
main();
</script>
</body>
</html>