Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Image Plot MNIST dataset

My data set is the MNIST from Kaggle

I am trying to use the image function to visualise say the first digit in the training set. Unfortunately I am getting the following error:

>image(1:28, 1:28, im, col=gray((0:255)/255))
Error in image.default(1:28, 1:28, im, col = gray((0:255)/255)) : 
'z' must be numeric or logical

Adding a few codes:

rawfile<-read.csv("D://Kaggle//MNIST//train.csv",header=T) #Reading the csv file
im<-matrix((rawfile[1,2:ncol(rawfile)]), nrow=28, ncol=28) #For the 1st Image

image(1:28, 1:28, im, col=gray((0:255)/255))

Error in image.default(1:28, 1:28, im, col = gray((0:255)/255)) : 
'z' must be numeric or logical
like image 646
Anurag H Avatar asked Jun 21 '16 20:06

Anurag H


People also ask

What is the MNIST dataset?

It is a large database of handwritten digits that is commonly used for training various image processing systems. The MNIST dataset is one of the most common datasets used for image classification and accessible from many different sources. In fact, even Tensorflow and Keras allow us to import and download the MNIST dataset directly from their API.

How to use matplotlib for image classification in MNIST?

Let’s try displaying the images in the MNIST dataset. Start by importing Matplotlib. To plot the data use the following piece of code : What’s next? Now that you have imported the MNIST dataset, you can use it for image classification. When it comes to the task of image classification, nothing can beat Convolutional Neural Networks (CNN).

How to load MNIST data in keras?

The easiest way to load the data is through Keras. MNIST dataset consists of training data and testing data. Each image is stored in 28X28 and the corresponding output is the digit in the image.

What is the dimension of each individual input vector in MNIST?

Each individual input vector is of the dimension [28 X 28]. Each individual output vector is of the dimension [ 1]. 2. Plotting the MNIST Dataset Let’s try displaying the images in the MNIST dataset.


1 Answers

At the moment your im is a matrix of characters. You need to convert it to a matrix of numbers, e.g. by issuing im_numbers <- apply(im, 2, as.numeric).

You can then issue image(1:28, 1:28, im_numbers, col=gray((0:255)/255)).

like image 114
skhan Avatar answered Oct 14 '22 10:10

skhan