Skip to content

Instantly share code, notes, and snippets.

@GantMan
Last active September 14, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GantMan/78189f19457449a09ecc05eb927f686c to your computer and use it in GitHub Desktop.
Save GantMan/78189f19457449a09ecc05eb927f686c to your computer and use it in GitHub Desktop.
Dogs N Cats
// https://www.cs.toronto.edu/~kriz/cifar.html
import * as DogsNCats from "dogs-n-cats"
// Creates a 1,000 dog and 1,000 cat images in memory
const DC = await DogsNCats.load()
// 4/5 Train/Test
DC.training.length // 1600
DC.test.length // 400
// Get 1000 random training images
// images is a stacked tensor set of 3D tensors
// labels is a tensor of 0s and 1s (0 is dog, 1 is cat)
const [images, labels] = DC.training.get(1000)
// single random dog 3D tensor
const [dogTensor, dogLabels] = DC.dogs.get()
// 3 random cat tensors stacked (4D), and 1D tensor of answers
const [catTensors, catLabels] = DC.cat.get(3)
// FAST! but non-random
const sameImages = DC.training.getOrdered(1000)
// Draw a dataset to a canvas
const gridX = 20
const gridY = 3
DC.gridShow(catTensors, displayCanvas, gridX, gridY, {scale:1.5, grow:true})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment