Skip to content

Instantly share code, notes, and snippets.

@padamson
Created October 16, 2016 00:14
Show Gist options
  • Save padamson/1cdf6e430a1fb82c096539188833bacf to your computer and use it in GitHub Desktop.
Save padamson/1cdf6e430a1fb82c096539188833bacf to your computer and use it in GitHub Desktop.
Display four random digits from MNIST database
mnist <- read.csv("data/mnist_small.csv",
colClasses = c(label = "factor"))
displayMnistSamples <- function(x) {
for(i in x){
y = as.matrix(mnist[i, 2:785])
dim(y) = c(28, 28)
image( y[,nrow(y):1], axes = FALSE, col = gray(0:255 / 255))
text( 0.2, 0, mnist[i,1], cex = 3, col = 2, pos = c(3,4))
}
}
par( mfrow = c(1,4), mai = c(0,0,0,0.1))
displayMnistSamples(sample(1:length(mnist),4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment