así que estuve revisando un proyecto simple de Tensorflow como punto de partida para aprender, y encontré uno que es muy "casual" y corto. Es un verificador de postura vertical, capaz de aprender (agregar ejemplo) sobre la marcha en tiempo de ejecución, e inmediatamente usar esa nueva información para inferir poses.
El sitio web de demostración: https://aaryanporwal.github.io/uprighthelper/
El repositorio: https://github.com/aaryanporwal/uprighthelper
Problema relevante: https://github.com/aaryanporwal/uprighthelper/issues/5
Una vez que ejecutas el programa (y haces clic en el botón Correcto/Incorrecto), el uso de la memoria aumenta de forma rápida y constante. A partir de 500 MB, a 1,5 GB en menos de 1 minuto y hasta 5 GB en mi prueba (cualquier RAM libre en ese momento). De media, sube 100 MB en 16 s.
Las partes principales del código.
const classifier = knnClassifier.create(); const webcamElement = document.getElementById('webcam'); let net; var audio = new Audio('audio_file.mp3'); async function app() { console.log('Loading mobilenet..'); // Load the model. net = await mobilenet.load(); console.log('Sucessfully loaded model'); await setupWebcam(); // Reads an image from the webcam and associates it with a specific class // index. const addExample = classId => { // Get the intermediate activation of MobileNet 'conv_preds' and pass that // to the KNN classifier. const activation = net.infer(webcamElement, 'conv_preds'); // Pass the intermediate activation to the classifier. classifier.addExample(activation, classId); }; // When clicking a button, add an example for that class. document.getElementById('class-a').addEventListener('click', () => addExample(0)); document.getElementById('class-b').addEventListener('click', () => addExample(1)); while (true) { if (classifier.getNumClasses() > 0) { // Get the activation from mobilenet from the webcam. const activation = net.infer(webcamElement, 'conv_preds'); // Get the most likely class and confidences from the classifier module. const result = await classifier.predictClass(activation); const classes = ['A', 'B']; if(classes[result.classIndex]=="B"){ await audio.play(); document.body.style.backgroundColor = "rgb(168, 63, 63)"; } else{ document.body.style.backgroundColor = "rgb(80, 168, 80)"; } } await tf.nextFrame(); } } // Webcam permission and stuff // ... app();