tutor: temirlan zharkynbek elective in ai...

20
Elective in AI Tensorflow: TensorFlow 2.0 Tutorial Tutor: Temirlan Zharkynbek

Upload: others

Post on 30-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Elective in AITensorflow: TensorFlow 2.0 Tutorial

Tutor: Temirlan Zharkynbek

Page 2: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Tensorflow 2.0x

Pagina 2

Page 3: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Example #1: from official webpage of Tensorflow

Pagina 3

Page 4: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

tf.function

Pagina 4

Page 5: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Training

Pagina 5

Page 6: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Use tf.GradientTape to train the model:

Pagina 6

Page 7: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

tf.function (explanation 1)

Pagina 7

Page 8: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

tf.function (explanation 2)

Pagina 8

Page 9: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

tf.GradientTape (explanation)

Pagina 9

Page 10: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Tensorflow

This tutorial walks you through the process of building a simple CIFAR-10 image classifier using deep learning. In this tutorial, we will:

● Define a model● Set up a data pipeline● Train the model● Accelerate training speed with multiple GPUs● Add callbacks for monitoring progress/updating learning schedules

Pagina 10

Page 11: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Defining a model

Pagina 11

Page 12: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Setting up a data pipeline

Pagina 12

● Loading: Copying the dataset (e.g. images and labels) from storage into the program's memory.

● Preprocessing: transforming the dataset. For example, in image classification, we might resize, whiten, shuffle, or batch images.

● Feeding: shoveling examples from a dataset into a training loop.

Page 13: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

The tf.data.Dataset class

Pagina 13

The TensorFlow Dataset class serves two main purposes:

● It acts as a container that holds training data.● It can be used to perform alterations on elements of the training data.

Page 14: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Data augmentation

Pagina 14

Let's augment the CIFAR-10 dataset by performing the following steps on every image:

● Pad the image with a black, four-pixel border.● Randomly crop a 32 x 32 region from the padded image.● Flip a coin to determine if the image should be horizontally flipped.

Page 15: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Blocks of the Residual Networks (ResNet)

Pagina 15

Page 16: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Training the model and #GPU

Pagina 16

A Keras model needs to be compiled before training. Compilation essentially defines three things: the loss function, the optimizer and the metrics for evaluation:

Page 17: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Setting up a data pipeline

Pagina 17

● Loading: Copying the dataset (e.g. images and labels) from storage into the program's memory.

● Preprocessing: transforming the dataset. For example, in image classification, we might resize, whiten, shuffle, or batch images.

● Feeding: shoveling examples from a dataset into a training loop.

Page 18: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Tensorboard & Learning rate schedule

Pagina 18

Page 19: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

Model fit

Pagina 19

Page 20: Tutor: Temirlan Zharkynbek Elective in AI …users.diag.uniroma1.it/~alcorlab/sites/default/files...Tensorflow This tutorial walks you through the process of building a simple CIFAR-10

References

Pagina 20

● https://lambdalabs.com/blog/tensorflow-2-0-tutorial-01-image-classification-basics/

● https://github.com/tensorflow/docs/blob/master/site/en/tutorials/quickstart/advanced.ipynb