2
$\begingroup$

I am a noob in machine learning and trying to build a classifier using keras by following this tutorial machine learning mastery tutorial

I want to build a classifier based on MLP like in classification of MNIST using MLP for CIFAR-10 data set.Like in MNIST data set the 28*28 images to a 784 vector is given as a input to the neural network. Like wise how should I frame the data in CIFAR-10 should it be changed in the 36*36 pixels rgb values to an array? or what type of array should I make to give as a input to the MLP network?

$\endgroup$
4
$\begingroup$

MNIST has 28x28 pixel greyscale images, so there are $28\times28 = 784$ features per image.

CIFAR10 contains colour images that are 32x32 pixels. At first glance it may seem like there are only $32\times32 = 1024$ features per image, but there are red, blue and green channels in the image, which means each image is actually $3\times32\times32 = 3072$ features.

Usually, these channels are arranged as three separate 32x32 pixel images, rather than a single 32x32 image with RGB pixels. In keras, you can load the CIFAR10 dataset like so:

from keras.datasets import cifar10

(x_train, y_train), (x_test, y_test) = cifar10.load_data()

However, this will load the train and test dataset in the shape (num_samples, 3, 32, 32). In order to input these into an MLP, we need to flatten the channels and pixel arrays to form an array of shape (num_samples, 3072), just like with MNIST. We can do this in python like so:

x_train = x_train.reshape(-1, 3072)
x_test = x_test.reshape(-1, 3072)
$\endgroup$
2
  • $\begingroup$ How does this reshape work I read in documentation that the np.reshpae(array_to_be_reshaped ,new shape dim,order).Can you please explain your reshape docs.scipy.org/doc/numpy-1.13.0/reference/generated/… $\endgroup$
    – Boris
    Nov 8 '17 at 4:34
  • $\begingroup$ @Boris You could do it that way too, by using x_train = np.reshape(x_train, (-1, 3072)). They are both equivalent. $\endgroup$ Nov 8 '17 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.