Hi, I have a problem with this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BlazeFace avec une image importée</title>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/blazeface"></script>
<style>
#canvas {
max-width: 500px;
}
</style>
</head>
<body>
<input type="file" accept="image/*" onchange="detectFaces(this)">
<p>Nombre de visages détectés : <span id="numFaces"></span></p>
<canvas id="canvas"></canvas>
<script>
async function detectFaces(input) {
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const img = new Image();
img.src = URL.createObjectURL(input.files[0]);
await img.decode();
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const model = await blazeface.load();
const predictions = await model.estimateFaces(canvas);
document.getElementById('numFaces').innerText = predictions.length;
for (let i = 0; i < predictions.length; i++) {
const start = predictions[i].topLeft;
const end = predictions[i].bottomRight;
const size = [end[0] - start[0], end[1] - start[1]];
ctx.beginPath();
ctx.rect(start[0], start[1], size[0], size[1]);
ctx.strokeStyle = 'red';
ctx.lineWidth = 2;
ctx.stroke();
}
}
</script>
</body>
</html>
BlazeFace is an ia of tensorflow.js supposed to recognize faces. But here when I put an image, it is displayed but no analysis is done.
console error (google chrome):
Uncaught (in promise) TypeError: n.loadGraphModel is not a function
at Object.<anonymous> (blazeface:17:7074)
at blazeface:17:1563
at Object.next (blazeface:17:1668)
at blazeface:17:606
at new Promise (<anonymous>)
at r (blazeface:17:354)
at t.load (blazeface:17:6893)
at detectFaces (blazeface.html:28:39)
(anonymous) @ blazeface:17
(anonymous) @ blazeface:17
(anonymous) @ blazeface:17
(anonymous) @ blazeface:17
r @ blazeface:17
t.load @ blazeface:17
detectFaces @ blazeface.html:28
await in detectFaces (async)
onchange @ blazeface.html:15
Thanks to you