Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Machine Learning on the Web

Avatar for Galuh Sahid Galuh Sahid
September 28, 2019

Machine Learning on the Web

Slide deck for the talk "Machine Learning on the Web" at JSDay ID

GitHub repository: https://github.com/galuhsahid/ml-on-the-web

Avatar for Galuh Sahid

Galuh Sahid

September 28, 2019
Tweet

More Decks by Galuh Sahid

Other Decks in Programming

Transcript

  1. Model Representasi matematis dari sebuah proses di dunia nyata 2000*jumlah

    lantai + … + 5000*jumlah kamar = harga rumah error=0.2
  2. Model Representasi matematis dari sebuah proses di dunia nyata 2000*jumlah

    lantai + … + 5000*jumlah kamar = harga rumah 3000*jumlah lantai + … + 6000*jumlah kamar = harga rumah error=0.2 error=0.1
  3. “A WebGL a elerated JavaS ript library for training and

    deploying ML models.” TensorFlow.js Ma hine learning dengan JavaS ript?
  4. <html> <head> <meta charset="UTF-8"> <title>Klasifikasi Gambar dengan ml5.js</title> <script src="https://unpkg.com/[email protected]/dist/

    ml5.min.js"></script> </head> <body> … <script src="sketch.js"></script> </body> </html> index.html
  5. sket h.js let classifier; const loadModel = async (modelName) =>

    { try { classifier = await ml5.imageClassifier(modelName); } catch (e) { console.error(e); } … };
  6. sket h.js let classifier; const loadModel = async (modelName) =>

    { try { classifier = await ml5.imageClassifier(modelName); } catch (e) { console.error(e); } … }; Darknet Darknet-tiny MobileNet
  7. sket h.js const image = document.getElementById("image"); … const getPrediction =

    async (input) => { try { let results = await classifier.classify(input); return results; } catch (e) { console.error(e); } };
  8. sket h.js const image = document.getElementById(“image"); … const getPrediction =

    async (input, classifier) => { try { let results = await classifier.classify(input); return results; } catch (e) { console.error(e); } };
  9. sket h.js const startWebcam = async () => { try

    { stream = await navigator.mediaDevices.getUserMedia( { video: true }); video.srcObject = stream; video.play(); getPrediction(video); } catch (e) { console.error(e); } };
  10. sket h.js const startWebcam = async () => { try

    { stream = await navigator.mediaDevices.getUserMedia( { video: true }); video.srcObject = stream; video.play(); getPrediction(video); } catch (e) { console.error(e); } }; MediaDevi es.getUserMedia()
  11. index.html <html> … <img src="images/rock.svg" alt="Rock" width="100" height="100" /><br />

    <p><span id="amountOfRockImages">0</ span> Rock Images</p> <p><button id="RockButton" class="button">Add Rock</button></p> </html>
  12. index.html <html> … <img src="images/rock.svg" alt="Rock" width="100" height="100" /><br />

    <p><span id="amountOfRockImages">0</ span> Rock Images</p> <p><button id="RockButton" class="button">Add Rock</button></p> </html>
  13. index.html <html> … <img src="images/rock.svg" alt="Rock" width="100" height="100" /><br />

    <p><span id="amountOfRockImages">0</ span> Rock Images</p> <p><button id="RockButton" class="button">Add Rock</button></p> … <button id="train" class="button">Train Model</button> </html>
  14. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = await ml5.featureExtractor("MobileNet"); classifier = await featureExtractor.classification(video, { numLabels: 3 }); } catch (e) { console.error(e); } };
  15. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = await ml5.featureExtractor("MobileNet"); classifier = await featureExtractor.classification(video, { numLabels: 3 }); } catch (e) { console.error(e); } }; Jenis model
  16. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = await ml5.featureExtractor("MobileNet"); classifier = await featureExtractor.classification(video, { numLabels: 3 }); } catch (e) { console.error(e); } }; Input
  17. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = await ml5.featureExtractor("MobileNet"); classifier = await featureExtractor.classification(video, { numLabels: 3 }); } catch (e) { console.error(e); } }; jumlah kelas
  18. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = ml5.featureExtractor("MobileNet"); classifier = featureExtractor.classification(video, { nu mLabels: 3 }); } catch (e) { console.error(e); } }; MobileNet Bicycle (0.373) Cup (0.232) Vacuum (0.121)
  19. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = ml5.featureExtractor("MobileNet"); classifier = featureExtractor.classification(video, { nu mLabels: 3 }); } catch (e) { console.error(e); } }; MobileNet Bicycle (0.373) Cup (0.232) Vacuum (0.121) x
  20. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = ml5.featureExtractor("MobileNet"); classifier = featureExtractor.classification(video, { nu mLabels: 3 }); } catch (e) { console.error(e); } }; MobileNet Rock (0.923) Paper (0.422) Scissors (0.231)
  21. sket h.js let classifier; const loadModel = async () =>

    { try { featureExtractor = ml5.featureExtractor("MobileNet"); classifier = featureExtractor.classification(video, { nu mLabels: 3 }); } catch (e) { console.error(e); } }; jumlah kelas https://www.mathworks.com/solutions/deep-learning/convolutional-neural-network.html
  22. sket h.js var RockButton = document.getElementById(“RockButton") … RockButton.onclick = function()

    { classifier.addImage(video, ”Rock”); amountOfRockImages.innerText = Number(amountOfRockImages.i nnerText) + 1; };
  23. sket h.js const trainModel = async () => { try

    { await classifier.train(function(lossValue) { if (lossValue) { totalLoss = lossValue; loss.innerHTML = "Loss: " + totalLoss; } else { loss.innerHTML = "Training done! Final loss: " + tot alLoss; } }); } catch(e) { console.error(e); } };
  24. sket h.js const trainModel = async () => { try

    { await classifier.train(function(lossValue) { if (lossValue) { totalLoss = lossValue; loss.innerHTML = "Loss: " + totalLoss; } else { loss.innerHTML = "Training done! Final loss: " + tot alLoss; } }); } catch(e) { console.error(e); } };
  25. sket h.js const getPlayerResult = async video => { try

    { let results = await classifier.classify(video); if (results && results[0]) { return results[0].label; } } catch (e) { console.error(err); } };
  26. sket h.js const getPlayerResult = async video => { try

    { let results = await classifier.classify(video); if (results && results[0]) { return results[0].label; } } catch (e) { console.error(err); } };
  27. Klasifikasi suara: Dataset Spee h ommands Dataset Yes No Up

    Down Left Right Go Stop 0-9 Unknown word Ba kground noise
  28. Klasifikasi suara NN Prediction: Up (0.86) Sound icon by Amiryshakiel

    from the Noun Project https://www.tensorflow.org/tutorials/sequences/audio_recognition
  29. sket h.js const options = { probabilityThreshold: 0.98 }; …

    const loadModel = async() => { try { classifier = await ml5.soundClassifier('SpeechCommands18 w', options); } catch (e) { console.error(e); } };
  30. sket h.js const getPrediction = async() => { try {

    await classifier.classify(scrollPage); } catch (e) { console.error(e); } };
  31. sket h.js function scrollPage(error, results) { if (results[0].label == 'down')

    { lastPosition = lastPosition + scrollBy; } else if (results[0].label == 'up') { lastPosition = lastPosition - scrollBy; } lastPosition = Math.max(0, lastPosition); window.scroll(0, lastPosition); };
  32. Selanjutnya • A Beginner’s Guide to Machine Learning in JavaScript

    oleh Daniel Shiffman • Magenta.js (generating music & art) • Kursus Coursera: Machine Learning oleh Andrew Ng • Beyond the web: machine learning + hardware • Source code ml5.js • Bias & etika pembelajaran mesin • Referensi buku: Weapons of Math Destruction oleh Cathy O’Neil