Telegram
- 8 ответов
- 0 вопросов
4
Вклад в тег
script.async = false;
// Functions
const loadedScripts = new Set();
async function loadScript(url) {
if (loadedScripts.has(url)) return;
const script = document.createElement('script');
script.src = url;
script.async = false;
document.head.append(script);
return new Promise((resolve, reject) => {
script.addEventListener('load', () => {
loadedScripts.add(url); resolve();
});
script.addEventListener('error', () => reject(
new Error(`Error loading script: ${url}`)
));
});
}
async function loadImage(url) {
const image = new Image();
image.src = url;
image.crossOrigin = 'anonymous';
return new Promise((resolve, reject) => {
image.addEventListener('load', () => {
resolve(image);
});
image.addEventListener('error', () => reject(
new Error(`Error loading image: ${url}`)
));
});
}
// Example
const image = loadImage('https://habrastorage.org/r/w1560/getpro/habr/upload_files/799/62f/375/79962f375d90db7f7d926ff40d623456.png');
await Promise.all([
loadScript('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core'),
loadScript('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter'),
loadScript('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl'),
loadScript('https://cdn.jsdelivr.net/npm/@tensorflow-models/face-landmarks-detection@1.0.6/dist/face-landmarks-detection.min.js')
]);
const model = faceLandmarksDetection.SupportedModels.MediaPipeFaceMesh;
const detectorConfig = {
runtime: 'tfjs',
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh'
};
const detector = await faceLandmarksDetection.createDetector(model, detectorConfig);
const faces = await detector.estimateFaces(await image);
console.log(faces);