Reputation: 63
i'm new to NNs with Python and Tensorflow, and I'm trying to create the inputs for my CNN. I have CIFAR10 dataset, a 50000x3072 list in Python (a list containing 50000 lists of 3072 elements), for the training images, and i'm not using the CIFAR10 dataset from keras. The CNN is the same used for the basic TF example: https://www.tensorflow.org/tutorials/images/cnn Every 3072 elements list has the following organization: the first 1024 elements are for the first color channel, the seconds 1024 for the second color channel and so on. I want to organize this list using a numpy array in the same way used in keras (an np array of 32 rows, each containing 32 np arrays of 3-dimension lists (3 color channels per pixel)).
I tried to use reshape and other basic functions but i'm not sure what to do to obtain the result.
Upvotes: 2
Views: 1239
Reputation:
To convert a Data from size of (50000,3072) to that required for CNN, you can use tf.reshape
as shown below:
!pip install tensorflow==2.1
import tensorflow as tf
import numpy as np
tf.__version__
a = tf.constant(np.zeros((50000,3072)))
a.shape #TensorShape([50000, 3072])
b = tf.reshape(a, [-1,32,32,3])
b.shape #TensorShape([50000, 32, 32, 3])
And in the First Layer of the CNN, you can specify the Input shape as mentioned below:
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
For more information about tf.reshape
, please refer this Tensorflow Page.
For more information about CNN on CIFAR Dataset, please refer this CNN Tutorial in Tensorflow Site.
Upvotes: 3