TensorFlow 2 tutorials and guides on the tensorflow.org are great resources for learning and practicing neutral networks. But, since they are provided by many authors, the styles of presenting the materials are inevitably diverse.
Various programming styles seem to be overwhelming for starting learners even though they help us learn different approaches to the same tasks.
The purpose of this posting is to re-organize programming codes used in TensorFlow 2 tutorials and guides so that they can be utilized for practical learning examples of TensorFlow 2.
We start from how to import datasets into TensorFlow. 3 different approaches are used in the tutorials and guides.
The easiest way. Just load the data from predefined modules.
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
Loading the dataset returns four NumPy arrays:
train_images
and train_labels
arrays are the training set—the data the model uses to learn.test_images
, and test_labels
arrays.The images are 28x28 NumPy arrays, with pixel values ranging from 0 to 255. The labels are an array of integers, ranging from 0 to 9. These correspond to the class of clothing the image represents.
Note: You need to know the tuples.
2. Tutorial > ML basics with Keras > Save and load
(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data()
train_labels = train_labels[:1000]
test_labels = test_labels[:1000]
train_images = train_images[:1000].reshape(-1, 28 * 28) / 255.0
test_images = test_images[:1000].reshape(-1, 28 * 28) / 255.0
#tensorflow #artificial-intelligence #dataset-api #machine-learning #keras