Skip to content

Instantly share code, notes, and snippets.

@Marina-Miranovich
Created November 14, 2018 21:03
Show Gist options
  • Save Marina-Miranovich/47c418e8296b12e1436c908e803e05ed to your computer and use it in GitHub Desktop.
Save Marina-Miranovich/47c418e8296b12e1436c908e803e05ed to your computer and use it in GitHub Desktop.
code_snippet_11 for "Playing Mortal Kombat with TensorFlow.js. Transfer learning and data augmentation" translation
const punches = require('fs')
.readdirSync(Punches)
.filter(f => f.endsWith('.jpg'))
.map(f => `${Punches}/${f}`);
const kicks = require('fs')
.readdirSync(Kicks)
.filter(f => f.endsWith('.jpg'))
.map(f => `${Kicks}/${f}`);
const others = require('fs')
.readdirSync(Others)
.filter(f => f.endsWith('.jpg'))
.map(f => `${Others}/${f}`);
const ys = tf.tensor2d(
new Array(punches.length)
.fill([1, 0, 0])
.concat(new Array(kicks.length).fill([0, 1, 0]))
.concat(new Array(others.length).fill([0, 0, 1])),
[punches.length + kicks.length + others.length, 3]
);
const xs: tf.Tensor2D = tf.stack(
punches
.map((path: string) => mobileNet(readInput(path)))
.concat(kicks.map((path: string) => mobileNet(readInput(path))))
.concat(others.map((path: string) => mobileNet(readInput(path))))
) as tf.Tensor2D;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment