pdfcoffee

soumyasankar99
from soumyasankar99 More from this publisher
09.05.2023 Views

[ 583 ]Chapter 16The execution is super-fast on a TPU as every single iteration takes about 2 seconds:Epoch 1/10INFO:tensorflow:New input shapes; (re-)compiling: mode=train (# ofcores 8), [TensorSpec(shape=(1024,), dtype=tf.int32, name=None),TensorSpec(shape=(1024, 28, 28, 1), dtype=tf.float32, name=None),TensorSpec(shape=(1024, 10), dtype=tf.float32, name=None)]INFO:tensorflow:Overriding default placeholder.INFO:tensorflow:Remapping placeholder for inputInstructions for updating:Use tf.cast instead.INFO:tensorflow:Started compilingINFO:tensorflow:Finished compiling. Time elapsed: 2.567350149154663 secsINFO:tensorflow:Setting weights on TPU model.60/60 [==============================] - 8s 126ms/step - loss: 0.9622 -acc: 0.6921Epoch 2/1060/60 [==============================] - 2s 41ms/step - loss: 0.2406 -acc: 0.9292Epoch 3/1060/60 [==============================] - 3s 42ms/step - loss: 0.1412 -acc: 0.9594Epoch 4/1060/60 [==============================] - 3s 42ms/step - loss: 0.1048 -acc: 0.9701Epoch 5/1060/60 [==============================] - 3s 42ms/step - loss: 0.0852 -acc: 0.9756Epoch 6/1060/60 [==============================] - 3s 42ms/step - loss: 0.0706 -acc: 0.9798Epoch 7/1060/60 [==============================] - 3s 42ms/step - loss: 0.0608 -acc: 0.9825Epoch 8/1060/60 [==============================] - 3s 42ms/step - loss: 0.0530 -acc: 0.9846Epoch 9/1060/60 [==============================] - 3s 42ms/step - loss: 0.0474 -acc: 0.9863

Tensor Processing UnitEpoch 10/1060/60 [==============================] - 3s 42ms/step - loss: 0.0418 -acc: 0.9876<tensorflow.python.keras.callbacks.History at 0x7fbb3819bc50>As you can see, running a simple MNIST model on TPUs is extremely fast. Eachiteration is around 3 seconds even if we have a CNN with 3 convolutions followedby two dense stages.Using pretrained TPU modelsGoogle offers a collection of models pretrained with TPUs available on GitHubTensorFlow/tpu repo (https://github.com/tensorflow/tpu). Models includeimage recognition, object detection, low-resource models, machine translation andlanguage models, speech recognition, and image generation. Whenever it is possible,my suggestion is to start with a pretrained model [6], and then fine tune it or applysome form of transfer learning. As of September 2019, the following models areavailable:Image Recognition,Segmentation, and moreMachine Translationand Language ModelsSpeechRecognitionImageGenerationImage Recognition• AmoebaNet-DMachine Translation(transformer based)ASRTransformerImageTransformer• ResNet-50/101/152/2000• Inception v2/v3/v4Sentiment AnalysisDCGANObject Detection• RetinaNet• Mask R-CNN(transformer based)Question AnswerGANImage Segmentation• Mask R-CNN• DeepLabBert• RetinaNetLow-Resource Models• MnasNet• MobileNet• SqueezeNetTable 1: State-of-the-art collection of models pretrained with TPUs available on GitHub[ 584 ]

[ 583 ]

Chapter 16

The execution is super-fast on a TPU as every single iteration takes about 2 seconds:

Epoch 1/10

INFO:tensorflow:New input shapes; (re-)compiling: mode=train (# of

cores 8), [TensorSpec(shape=(1024,), dtype=tf.int32, name=None),

TensorSpec(shape=(1024, 28, 28, 1), dtype=tf.float32, name=None),

TensorSpec(shape=(1024, 10), dtype=tf.float32, name=None)]

INFO:tensorflow:Overriding default placeholder.

INFO:tensorflow:Remapping placeholder for input

Instructions for updating:

Use tf.cast instead.

INFO:tensorflow:Started compiling

INFO:tensorflow:Finished compiling. Time elapsed: 2.567350149154663 secs

INFO:tensorflow:Setting weights on TPU model.

60/60 [==============================] - 8s 126ms/step - loss: 0.9622 -

acc: 0.6921

Epoch 2/10

60/60 [==============================] - 2s 41ms/step - loss: 0.2406 -

acc: 0.9292

Epoch 3/10

60/60 [==============================] - 3s 42ms/step - loss: 0.1412 -

acc: 0.9594

Epoch 4/10

60/60 [==============================] - 3s 42ms/step - loss: 0.1048 -

acc: 0.9701

Epoch 5/10

60/60 [==============================] - 3s 42ms/step - loss: 0.0852 -

acc: 0.9756

Epoch 6/10

60/60 [==============================] - 3s 42ms/step - loss: 0.0706 -

acc: 0.9798

Epoch 7/10

60/60 [==============================] - 3s 42ms/step - loss: 0.0608 -

acc: 0.9825

Epoch 8/10

60/60 [==============================] - 3s 42ms/step - loss: 0.0530 -

acc: 0.9846

Epoch 9/10

60/60 [==============================] - 3s 42ms/step - loss: 0.0474 -

acc: 0.9863

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!