human/test/test-embedding.html

87 lines
4.5 KiB
HTML

<!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>
html { font-size: 10px; font-variant: small-caps; }
body { margin: 0; background: black; color: white; width: 100vw; }
</style>
</head>
<body>
<div style="position: fixed; top: 20px; right: 20px; background: #333333; padding: 10px">
<input type="checkbox" id="glShapesUniform" name="glShapesUniform" value="glShapesUniform">
<label for="glShapesUniform">Enable WebGL Uniforms for Shapes</label><br>
<input type="checkbox" id="glExpandedConv" name="glExpandedConv" value="glExpandedConv">
<label for="glExpandedConv">Enable WebGL Expanded Convolutions</label><br><br>
<button id="run">Run Test</button>
</div>
<pre id="log" style="line-height: 150%; overflow-x: hidden; white-space: pre-wrap"></pre>
<script type="module">
import { Human } from '../dist/human.esm.js';
const testConfig = {
debug: true,
async: false,
modelBasePath: 'https://vladmandic.github.io/human-models/models/',
cacheSensitivity: 0,
cacheModels: false,
warmup: 'face',
face: { iris: { enabled: false }, emotion: { enabled: false }, mesh: { enabled: true }, descriptior: { enabled: true } },
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() {
document.getElementById('run').disabled = true;
const human = new Human(testConfig);
await human.init();
const glShapesUniform = document.getElementById('glShapesUniform').checked;
const glExpandedConv = document.getElementById('glExpandedConv').checked
if (glShapesUniform) tf.env().set('WEBGL_USE_SHAPES_UNIFORMS', true);
if (glExpandedConv) tf.env().set('WEBGL_EXP_CONV', true);
await human.load();
await human.check();
let res;
res = await human.warmup({ warmup: 'none' });
if (Array.isArray(res?.face?.[0]?.embedding) && (res?.face?.[0]?.embedding.length === 1024)) res.face[0].embedding.length = 10;
const pass0 = res?.face?.[0]?.embedding?.[0] === 0 ? true : false;
log({ backend: human.tf.getBackend(), pass: pass0, warmup: human.config.warmup, gender: res?.face?.[0]?.gender, genderScore: res?.face?.[0]?.genderScore, age: res?.face?.[0]?.age, embedding: res?.face?.[0]?.embedding });
res = await human.warmup({ warmup: 'face' });
if (Array.isArray(res?.face?.[0]?.embedding) && (res?.face?.[0]?.embedding.length === 1024)) res.face[0].embedding.length = 10;
console.log('EEEE', res?.face?.[0]?.embedding?.[0]);
const pass1 = res?.face?.[0]?.embedding?.[0] === 0 ? true : false;
log({ backend: human.tf.getBackend(), pass: pass1, warmup: human.config.warmup, gender: res?.face?.[0]?.gender, genderScore: res?.face?.[0]?.genderScore, age: res?.face?.[0]?.age, embedding: res?.face?.[0]?.embedding });
res = await human.warmup({ warmup: 'body' });
if (Array.isArray(res?.face?.[0]?.embedding) && (res?.face?.[0]?.embedding.length === 1024)) res.face[0].embedding.length = 10;
const pass2 = res?.face?.[0]?.embedding?.[0] === 0 ? true : false;
log({ backend: human.tf.getBackend(), pass: pass2, warmup: human.config.warmup, gender: res?.face?.[0]?.gender, genderScore: res?.face?.[0]?.genderScore, age: res?.face?.[0]?.age, embedding: res?.face?.[0]?.embedding });
const pass = !pass0 && pass1 && pass2;
log({ test: 'complete', pass, glShapesUniform, glExpandedConv });
}
document.getElementById('run').addEventListener('click', main);
</script>
</body>
</html>