Created
November 14, 2018 21:01
-
-
Save Marina-Miranovich/7084d22f2835916d32e4dc4f0d818dc7 to your computer and use it in GitHub Desktop.
code_snippet_10 for "Playing Mortal Kombat with TensorFlow.js. Transfer learning and data augmentation" translation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const startInterval = (mobilenet, model) => () => { | |
setInterval(() => { | |
canvas.getContext('2d').drawImage(video, 0, 0); | |
grayscale(scale | |
.getContext('2d') | |
.drawImage( | |
canvas, 0, 0, canvas.width, | |
canvas.width / (ImageSize.Width / ImageSize.Height), | |
0, 0, ImageSize.Width, ImageSize.Height | |
)); | |
const [punching] = Array.from(( | |
model.predict(mobilenet(tf.fromPixels(scale))) as tf.Tensor1D) | |
.dataSync() as Float32Array); | |
const detect = (window as any).Detect; | |
if (punching >= 0.4) detect && detect.onPunch(); | |
}, 100); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment