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.

TensorFlow

An end-to-end open source machine learning platform for everyone. Discover TensorFlow’s flexible ecosystem of tools…

www.tensorflow.org

We start from how to import datasets into TensorFlow. 3 different approaches are used in the tutorials and guides.

I. Use tf.keras.datasets

The easiest way. Just load the data from predefined modules.

  1. Tutorials > ML basics with Keras > Basic image classification
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:

  • The train_images and train_labels arrays are the training set—the data the model uses to learn.
  • The model is tested against the test set, the 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

[TensorFlow 2] Garbage In, Garbage Out
1.55 GEEK