Skip to content

Instantly share code, notes, and snippets.

@Marina-Miranovich
Created November 14, 2018 21:01
Show Gist options
  • Save Marina-Miranovich/7084d22f2835916d32e4dc4f0d818dc7 to your computer and use it in GitHub Desktop.
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
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