Home >Technology peripherals >AI >Why can TensorFlow do machine learning development?

Why can TensorFlow do machine learning development?

WBOY
WBOYforward
2023-04-08 21:21:041641browse

Machine learning is a complex subject, but because machine learning frameworks (such as Google's TensorFlow) simplify the process of obtaining data, training models, providing predictions and improving future results, implementing machine learning is far less daunting than it once was. .

Why can TensorFlow do machine learning development?

Created by the Google Brain team and initially released to the public in 2015, TensorFlow is an open source library for numerical computing and large-scale machine learning. TensorFlow bundles together a wide range of machine learning and deep learning models and algorithms (also known as neural networks) and makes them useful through common programming metaphors. It provides a convenient front-end API for building applications using Python or JavaScript while executing them in high-performance C.

TensorFlow competes with frameworks such as PyTorch and Apache MXNet to train and run deep neural networks for handwritten digit classification, image recognition, word embeddings, recurrent neural networks, sequence-to-sequence models for machine translation, Natural Language Processing and PDE (Partial Differential Equations) based simulations. Best of all, TensorFlow supports production predictions at scale, using the same model for training.

TensorFlow also has an extensive library of pre-trained models that can be used in your own projects. You can also use the code in the TensorFlow Model Park as examples of best practices for training your own models.

How TensorFlow works

TensorFlow allows developers to create data flow graphs—structures that describe how data moves through a graph or series of processing nodes. Each node in the graph represents a mathematical operation, and each connection or edge between nodes is a multidimensional data array, or tensor.

TensorFlow applications can run on most convenient targets: local machines, clusters in the cloud, iOS and Android devices, CPUs, or GPUs. If you use Google's own cloud, you can run TensorFlow on Google's custom TensorFlow Processing Unit (TPU) chip for further acceleration. However, the resulting models created by TensorFlow can be deployed on most devices used to provide predictions.

TensorFlow 2.0 was released in October 2019, with various improvements to the framework based on user feedback, making it easier to use (for example, by using the relatively simple KerasAPI for model training) and higher performance. Distributed training is easier to run thanks to new APIs, and support for TensorFlow Lite makes it possible to deploy models on a wider variety of platforms. However, code written for earlier versions of TensorFlow must be rewritten—sometimes only slightly, sometimes significantly—to take maximum advantage of new TensorFlow 2.0 features.

The trained model can be used to provide predictions as a service through a Docker container using REST or gRPC API. For more advanced service scenarios, you can use Kubernetes

Using TensorFlow with Python

TensorFlow provides all these capabilities to programmers through the Python language. Python is easy to learn and use, and it provides convenient ways to express how to couple high-level abstractions together. TensorFlow is supported on Python versions 3.7 to 3.10, and while it may work on earlier versions of Python, it is not guaranteed to do so.

Nodes and tensors in TensorFlow are Python objects, and TensorFlow applications themselves are Python applications. However, the actual mathematical operations are not performed in Python. The transformation libraries provided through TensorFlow are written as high-performance C binaries. Python simply directs the flow between the various parts and provides high-level programming abstractions to connect them together.

Advanced work in TensorFlow (creating nodes and layers and linking them together) uses the Keras library. The Keras API is deceptively simple; a basic three-layer model can be defined in less than 10 lines of code, and the same training code requires only a few lines of code. But if you want to "lift the veil" and do more fine-grained work, like writing your own training loops, you can do that.

Using TensorFlow with JavaScript

Python is the most popular language for working with TensorFlow and machine learning. But JavaScript is now also the first-class language for TensorFlow, and one of the huge advantages of JavaScript is that it runs anywhere there is a web browser.

TensorFlow.js (called the JavaScript TensorFlow library) uses the WebGL API to accelerate computations with any GPU available in the system. It can also be performed using a WebAssembly backend, which is faster than a regular JavaScript backend if you only run on the CPU, but it's best to use the GPU whenever possible. Pre-built models let you get simple projects up and running, giving you an idea of ​​how things work.

TensorFlow Lite

The trained TensorFlow model can also be deployed on edge computing or mobile devices, such as iOS or Android systems. The TensorFlow Lite toolset optimizes TensorFlow models to run well on such devices by allowing you to trade off model size and accuracy. Smaller models (i.e. 12MB vs. 25MB, or even 100 MB) are less accurate, but the loss in accuracy is usually small and offset by the speed and energy efficiency of the model.

Why use TensorFlow

The biggest benefit TensorFlow provides for machine learning development is abstraction. Developers can focus on overall application logic rather than dealing with the details of implementing algorithms or figuring out the correct way to connect the output of one function to the input of another. TensorFlow takes care of the details behind the scenes.

TensorFlow provides greater convenience for developers who need to debug and understand TensorFlow applications. Each graph operation can be evaluated and modified individually and transparently, rather than building the entire graph as a single opaque object and evaluating it at once. This so-called "eager execution mode" was available as an option in older versions of TensorFlow and is now standard.

TensorBoard Visualization Suite lets you inspect and analyze how your graphs are running through an interactive web-based dashboard. The Tensorboard.dev service (hosted by Google) lets you host and share machine learning experiments written in TensorFlow. It can be used for free to store up to 100M of scalar, 1GB of tensor data, and 1GB of binary object data. (Please note that any data hosted in Tensorboard.dev is public, so please do not use it for sensitive projects.)

TensorFlow also gains many advantages from the support of Google's top-notch commercial organizations. Google has driven the project's rapid growth and created many important products that make TensorFlow easier to deploy and use. The TPU chip described above for accelerating performance in Google Cloud is just one example.

Using TensorFlow for deterministic model training

Some details of TensorFlow implementation make it difficult to obtain completely deterministic model training results for some training jobs. Sometimes, a model trained on one system will be slightly different than a model trained on another system, even though they are provided with the exact same data. The reasons for this difference are tricky - one reason is how and where the random numbers are seeded; the other has to do with some non-deterministic behavior when using GPUs. The 2.0 branch of TensorFlow has an option to enable determinism throughout the entire workflow with a few lines of code. However, this feature comes at the cost of performance and should only be used when debugging workflows.

TensorFlow competes with PyTorch, CNTK and MXNet

TensorFlow competes with many other machine learning frameworks. PyTorch, CNTK, and MXNet are the three main frameworks that serve many of the same needs. Let’s take a quick look at where they stand out and fall short compared to TensorFlow:

  • PyTorch is built in Python and has many other similarities with TensorFlow: Hardware acceleration components under the hood , a highly interactive development model that allows out-of-the-box design work, and already contains many useful components. PyTorch is often a better choice for rapid development of projects that need to be up and running in a short time, but TensorFlow is better suited for larger projects and more complex workflows.
  • CNTK is the Microsoft Cognitive Toolkit, similar to TensorFlow in using graph structures to describe data flow, but it mainly focuses on creating deep learning neural networks. CNTK can handle many neural network jobs faster and has a wider API (Python, C, C#, Java). But currently it is not as easy to learn or deploy as TensorFlow. It is also only available under the GNU GPL 3.0 license, while TensorFlow is available under the more liberal Apache license. And CNTK has less positive developments. The last major version was in 2019.
  • Adopted by Amazon as the premier deep learning framework on AWS, Apache MXNet scales almost linearly across multiple GPUs and multiple machines. MXNet also supports a wide range of language APIs - Python, C, Scala, R, JavaScript, Julia, Perl, Go - although its native API is not as easy to use as TensorFlow. It also has a much smaller community of users and developers.


Original title:​​What is TensorFlow? The machine learning library explained​

The above is the detailed content of Why can TensorFlow do machine learning development?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete