apprentissage:bac
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteDernière révisionLes deux révisions suivantes | ||
apprentissage:bac [2020/06/08 16:07] – jbpuel | apprentissage:bac [2023/06/30 09:41] – jbpuel | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
L' | L' | ||
+ | < | ||
+ | < | ||
+ | <button type=" | ||
+ | < | ||
+ | <div id=" | ||
+ | <script src=" | ||
+ | <script src=" | ||
+ | <script type=" | ||
+ | // More API functions here: | ||
+ | // https:// | ||
+ | // the link to your model provided by Teachable Machine export panel | ||
+ | const URL = " | ||
+ | let model, webcam, ctx, labelContainer, | ||
+ | async function init() { | ||
+ | const modelURL = URL + " | ||
+ | const metadataURL = URL + " | ||
+ | |||
+ | // load the model and metadata | ||
+ | // Refer to tmImage.loadFromFiles() in the API to support files from a file picker | ||
+ | // Note: the pose library adds a tmPose object to your window (window.tmPose) | ||
+ | model = await tmPose.load(modelURL, | ||
+ | maxPredictions = model.getTotalClasses(); | ||
+ | |||
+ | // Convenience function to setup a webcam | ||
+ | const size = 200; | ||
+ | const flip = true; // whether to flip the webcam | ||
+ | webcam = new tmPose.Webcam(size, | ||
+ | await webcam.setup(); | ||
+ | await webcam.play(); | ||
+ | window.requestAnimationFrame(loop); | ||
+ | |||
+ | // append/get elements to the DOM | ||
+ | const canvas = document.getElementById(" | ||
+ | canvas.width = size; canvas.height = size; | ||
+ | ctx = canvas.getContext(" | ||
+ | labelContainer = document.getElementById(" | ||
+ | for (let i = 0; i < maxPredictions; | ||
+ | labelContainer.appendChild(document.createElement(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | async function loop(timestamp) { | ||
+ | webcam.update(); | ||
+ | await predict(); | ||
+ | window.requestAnimationFrame(loop); | ||
+ | } | ||
+ | |||
+ | async function predict() { | ||
+ | // Prediction #1: run input through posenet | ||
+ | // estimatePose can take in an image, video or canvas html element | ||
+ | const { pose, posenetOutput } = await model.estimatePose(webcam.canvas); | ||
+ | // Prediction 2: run input through teachable machine classification model | ||
+ | const prediction = await model.predict(posenetOutput); | ||
+ | |||
+ | for (let i = 0; i < maxPredictions; | ||
+ | const classPrediction = | ||
+ | prediction[i].className + ": " + prediction[i].probability.toFixed(2); | ||
+ | labelContainer.childNodes[i].innerHTML = classPrediction; | ||
+ | } | ||
+ | |||
+ | // finally draw the poses | ||
+ | drawPose(pose); | ||
+ | } | ||
+ | |||
+ | function drawPose(pose) { | ||
+ | if (webcam.canvas) { | ||
+ | ctx.drawImage(webcam.canvas, | ||
+ | // draw the keypoints and skeleton | ||
+ | if (pose) { | ||
+ | const minPartConfidence = 0.5; | ||
+ | tmPose.drawKeypoints(pose.keypoints, | ||
+ | tmPose.drawSkeleton(pose.keypoints, | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | </ |
apprentissage/bac.txt · Dernière modification : 2023/06/30 09:43 de jbpuel