Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Last active March 24, 2019 13:42
Show Gist options
  • Save NMZivkovic/557c06e3f3159df2b0ded4d996bacdb3 to your computer and use it in GitHub Desktop.
Save NMZivkovic/557c06e3f3159df2b0ded4d996bacdb3 to your computer and use it in GitHub Desktop.
async function singleImagePlot(image)
{
const canvas = document.createElement('canvas');
canvas.width = 28;
canvas.height = 28;
canvas.style = 'margin: 4px;';
await tf.browser.toPixels(image, canvas);
return canvas;
}
async function displayDataFunction(data, numOfImages = 10) {
const inputDataSurface =
tfvis.visor().surface({ name: 'Input Data Examples', tab: 'Input Data'});
const examples = data.nextDataBatch(numOfImages, true);
for (let i = 0; i < numOfImages; i++) {
const image = tf.tidy(() => {
return examples.xs
.slice([i, 0], [1, examples.xs.shape[1]])
.reshape([28, 28, 1]);
});
const canvas = await singleImagePlot(image)
inputDataSurface.drawArea.appendChild(canvas);
image.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment