Learn practical skills, build real-world projects, and advance your career
import tensorflow as tf
from tensorflow import keras

# double check your tf version
print(tf.__version__)

# get sampling data set
fashion_mnist = keras.datasets.mnist
(trainx, trainy), (testx, testy) = fashion_mnist.load_data()

print("GPU Available: ", tf.test.is_gpu_available())
2.0.0-alpha0 GPU Available: True
import matplotlib.pyplot as plt
imgplot = plt.imshow(trainx[0])
plt.show()
trainx = trainx / 255.0
testx  = testx / 255.0

print(trainx.shape)
print(trainy.shape)
print(testx.shape)
print(testy.shape)
Notebook Image
(60000, 28, 28) (60000,) (10000, 28, 28) (10000,)
# reshape your data dimension into 3D (28,28,1)
trainx= trainx.reshape(trainx.shape[0], 28, 28, 1).astype('float32')
testx = testx.reshape(testx.shape[0], 28, 28, 1).astype('float32')

print(trainx.shape)
print(testx.shape)
(60000, 28, 28, 1) (10000, 28, 28, 1)
# suggestion from Tutorial, shuffle dataset
TRAIN_BUF = 60000
BATCH_SIZE = 100
TEST_BUF = 10000

train_dataset = tf.data.Dataset.from_tensor_slices(trainx).shuffle(TRAIN_BUF).batch(BATCH_SIZE)
test_dataset = tf.data.Dataset.from_tensor_slices(testx).shuffle(TEST_BUF).batch(BATCH_SIZE)
from IPython.display import Image
from IPython.core.display import HTML 
Image(url= "https://i.imgur.com/j8MEca6.png")