 # Image Classification Dataset

In This example, X shape is (32,64,64,1).

• 32 is the number of examples in minibatch
• 64 is the heigth of image
• 64 is width of image
But where is the last dimension is refering to?

Hi @Harvinder_singh, “1” refers to the number of channel. Since this is a greyscale image, the number of channel will be 1, while a color image (with RGB channel) has a channel equaled to 3.

1 Like

Thanks @goldpiggy , Now I understood what is 1 referring here.

Which one is preferred? First divide into batches and then shuffle or first shuffle and then batch? Here the first one is coded and looks suspicious for me. Specially if batch_size is big, you would always have same training data in the batch and only the order of batches would change. This would create problems if for example training data are ordered by labels.
Check the result of this:
tmp = tf.data.Dataset.from_tensor_slices([1,1,1,2,2,2]).batch(3).shuffle(buffer_size = 6)

1 Like

I am literally scared by looking at the TensorFlow code provided here so I want to make it simple for others

``````# importing the libraries
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()

# get the first picture in train data
plt.imshow(x_train)

# data normalization to make everything between 0 and 1.
x_train = x_train.astype('float32') / 255
x_test = x_test.astype('float32') / 255

# Putting it all together
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()

# Divide all numbers by 255 so that all pixel values are between
# 0 and 1
x_train = x_train.astype('float32') / 255
x_test = x_test.astype('float32') / 255

# casting the label to int32`
y_train = tf.cast(y_train, 'int32')
y_test = tf.cast(y_test, 'int32')

return (
tf.data.Dataset.from_tensor_slices((x_train, y_train)).batch(batch_size).shuffle(len(x_train)),
tf.data.Dataset.from_tensor_slices((x_test, y_test)).batch(batch_size).shuffle(len(x_test))
)