pdfcoffee
TensorFlow for Mobile andIoT and TensorFlow.jsIn this chapter we will learn the basics of TensorFlow for Mobile and IoT (Internetof Things). We will briefly present TensorFlow Mobile and we will introduceTensorFlow Lite in more detail. TensorFlow Mobile and TensorFlow Lite areopen source deep learning frameworks for on-device inference. Some examplesof Android, iOS, and Raspberry PI applications will be discussed, together withexamples of deploying pretrained models such as MobileNet v1, v2, v3 (imageclassification models designed for mobile and embedded vision applications),PoseNet for pose estimation (a vision model that estimates the poses of peoplein image or video), DeepLab segmentation (an image segmentation model thatassigns semantic labels (for example, dog, cat, car) to every pixel in the inputimage), and MobileNet SSD object detection (an image classification model thatdetects multiple objects with bounding boxes). This chapter will conclude withan example of federated learning, a new machine learning framework distributedover millions of mobile devices that is thought to respect user privacy.TensorFlow MobileTensorFlow Mobile is a framework for producing code on iOS and Android. Thekey idea is to have a platform that allows you to have light models that don'tconsume too much device resources such as battery or memory. Typical examplesof applications are image recognition on the device, speech recognition, or gesturerecognition. TensorFlow Mobile was quite popular until 2018 but then becameprogressively less and less adopted in favor of TensorFlow Lite.[ 461 ]
TensorFlow for Mobile and IoT and TensorFlow.jsTensorFlow LiteTensorFlow Lite is a lightweight platform designed by TensorFlow. This platformis focused on mobile and embedded devices such as Android, iOS, and RaspberryPI. The main goal is to enable machine learning inference directly on the deviceby putting a lot of effort in three main characteristics: (1) small binary and modelsize to save on memory, (2) low energy consumption to save on the battery, and(3) low latency for efficiency. It goes without saying that battery and memory aretwo important resources for mobile and embedded devices. In order to achievethese goals, Lite uses a number of techniques such as Quantization, FlatBuffers,Mobile interpreter, and Mobile converter, which we are going to review briefly inthe following sections.QuantizationQuantization refers to a set of techniques that constrains an input made ofcontinuous values (such as real numbers) into a discrete set (such as integers).The key idea is to reduce the space occupancy of Deep Learning (DL) models byrepresenting the internal weight with integers instead of real numbers. Of course,this implies trading space gains for some amount of performance of the model.However, it has been empirically shown in many situations that a quantized modeldoes not suffer from a significant decay in performance. TensorFlow Lite is internallybuilt around a set of core operators supporting both quantized and floating-pointoperations.Model quantization is a toolkit for applying quantization. This operation is appliedto the representations of weights and, optionally, to the activations for both storageand computation. There are two types of quantization available:• Post-training quantization quantizes weights and the result of activationspost training.• Quantization-aware training allows for the training of networks that can bequantized with minimal accuracy drop (only available for specific CNNs).Since this is a relatively experimental technique, we are not going to discussit in this chapter but the interested reader can find more information in [1].TensorFlow Lite supports reducing the precision of values from full floats to halfprecisionfloats (float16) or 8-bit integers. TensorFlow reports multiple trade-offs interms of accuracy, latency, and space for selected CNN models (see Figure 1, source:https://www.tensorflow.org/lite/performance/model_optimization):[ 462 ]
- Page 446 and 447: Chapter 11Normally, the value is de
- Page 448 and 449: Chapter 11• The next question tha
- Page 450 and 451: Chapter 11This neural network takes
- Page 452 and 453: Chapter 11The MuJoCo environment re
- Page 454 and 455: Chapter 11We will first import the
- Page 456 and 457: Chapter 11The αα is the learning
- Page 458 and 459: Chapter 11We set up the global valu
- Page 460 and 461: Chapter 11else:return np.argmax(sel
- Page 462 and 463: Chapter 11DQN to play a game of Ata
- Page 464 and 465: Chapter 11self.model.add( Conv2D(64
- Page 466 and 467: Chapter 11Here the action A was sel
- Page 468 and 469: Chapter 11Image source: https://arx
- Page 470 and 471: Chapter 11A neural network is used
- Page 472: Chapter 1111. Details regarding ins
- Page 475 and 476: TensorFlow and Cloud• Scalability
- Page 477 and 478: TensorFlow and Cloud• Azure DevOp
- Page 479 and 480: TensorFlow and Cloud• Lambda: The
- Page 481 and 482: TensorFlow and Cloud• Deep Learni
- Page 483 and 484: TensorFlow and CloudEC2 on AmazonTo
- Page 485 and 486: TensorFlow and CloudCompute Instanc
- Page 487 and 488: TensorFlow and CloudYou just share
- Page 489 and 490: TensorFlow and CloudIn case you req
- Page 491 and 492: TensorFlow and CloudIt starts with
- Page 493 and 494: TensorFlow and CloudTFX librariesTF
- Page 495: TensorFlow and CloudReferences1. To
- Page 499 and 500: TensorFlow for Mobile and IoT and T
- Page 501 and 502: TensorFlow for Mobile and IoT and T
- Page 503 and 504: TensorFlow for Mobile and IoT and T
- Page 505 and 506: TensorFlow for Mobile and IoT and T
- Page 507 and 508: TensorFlow for Mobile and IoT and T
- Page 509 and 510: TensorFlow for Mobile and IoT and T
- Page 511 and 512: TensorFlow for Mobile and IoT and T
- Page 513 and 514: TensorFlow for Mobile and IoT and T
- Page 515 and 516: TensorFlow for Mobile and IoT and T
- Page 517 and 518: TensorFlow for Mobile and IoT and T
- Page 519 and 520: TensorFlow for Mobile and IoT and T
- Page 521 and 522: TensorFlow for Mobile and IoT and T
- Page 523 and 524: TensorFlow for Mobile and IoT and T
- Page 525 and 526: TensorFlow for Mobile and IoT and T
- Page 527 and 528: An introduction to AutoMLThat is pr
- Page 529 and 530: An introduction to AutoMLFeature co
- Page 531 and 532: An introduction to AutoMLThis Effic
- Page 533 and 534: An introduction to AutoMLGoogle Clo
- Page 535 and 536: An introduction to AutoMLThen, we c
- Page 537 and 538: An introduction to AutoMLOnce the d
- Page 539 and 540: An introduction to AutoMLIf your mo
- Page 541 and 542: An introduction to AutoMLClicking o
- Page 543 and 544: An introduction to AutoMLFigure 16:
- Page 545 and 546: An introduction to AutoMLYou can al
TensorFlow for Mobile and IoT and TensorFlow.js
TensorFlow Lite
TensorFlow Lite is a lightweight platform designed by TensorFlow. This platform
is focused on mobile and embedded devices such as Android, iOS, and Raspberry
PI. The main goal is to enable machine learning inference directly on the device
by putting a lot of effort in three main characteristics: (1) small binary and model
size to save on memory, (2) low energy consumption to save on the battery, and
(3) low latency for efficiency. It goes without saying that battery and memory are
two important resources for mobile and embedded devices. In order to achieve
these goals, Lite uses a number of techniques such as Quantization, FlatBuffers,
Mobile interpreter, and Mobile converter, which we are going to review briefly in
the following sections.
Quantization
Quantization refers to a set of techniques that constrains an input made of
continuous values (such as real numbers) into a discrete set (such as integers).
The key idea is to reduce the space occupancy of Deep Learning (DL) models by
representing the internal weight with integers instead of real numbers. Of course,
this implies trading space gains for some amount of performance of the model.
However, it has been empirically shown in many situations that a quantized model
does not suffer from a significant decay in performance. TensorFlow Lite is internally
built around a set of core operators supporting both quantized and floating-point
operations.
Model quantization is a toolkit for applying quantization. This operation is applied
to the representations of weights and, optionally, to the activations for both storage
and computation. There are two types of quantization available:
• Post-training quantization quantizes weights and the result of activations
post training.
• Quantization-aware training allows for the training of networks that can be
quantized with minimal accuracy drop (only available for specific CNNs).
Since this is a relatively experimental technique, we are not going to discuss
it in this chapter but the interested reader can find more information in [1].
TensorFlow Lite supports reducing the precision of values from full floats to halfprecision
floats (float16) or 8-bit integers. TensorFlow reports multiple trade-offs in
terms of accuracy, latency, and space for selected CNN models (see Figure 1, source:
https://www.tensorflow.org/lite/performance/model_optimization):
[ 462 ]