ROS and machine learning (1)-TensorFlow

ROS and machine learning (1)-TensorFlow

1. AlphaGo's brain-TensorFlow

The reason why AlphaGo can beat everyone is because it has a "most powerful brain", which is built on TensorFlow.
TensorFlow is a machine learning and deep learning framework open sourced by Google in November 2015, and it has attracted great attention when it appeared.
TensorFlow is not only an interface for implementing machine learning algorithms, but also a framework for executing machine learning algorithms. As shown in the figure, its front-end supports Python, C++, Go, Java and other development languages, and the back-end is implemented in C++, CUDA, etc. It can be transplanted on many heterogeneous systems, such as Android systems, iOS systems, ordinary CPU servers, and even large-scale GPU clusters.
Insert picture description here

In addition to executing deep learning algorithms, TensorFlow can also be used to implement many other algorithms, including linear regression, logistic regression, random forest, etc. The application scenarios of large-scale deep learning models established by TensorFlow are also very wide, including speech recognition, natural language processing, computer vision, robot control, information extraction, drug research and development, etc. The models developed using TensorFlow have also obtained the most cutting-edge in these fields Results.

2. TensorFlow basics

2.1 Install TensorFlow

The installation of TensorFlow can be done directly using the Python package management tool pip. First use the following command to install the pip tool in the Ubuntu system:

sudo apt-get install python-pip python-dev

Then set the download address of TensorFlow and install it:

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/apu/tensorflow-1.4.0-cp27-none-linux_x86_64.whl
sudo pip install --upgrade $TF_BINARY_URL

During the installation process, you may encounter a pip version that is too low and cause the installation to fail. You need to use the following command to update to a new version of pip:

sudo -H pip install --upgrade pip

Then re-run the above TensorFlow installation command, the terminal installation progress is displayed as shown in the figure.
Insert picture description here
The installation time depends on the network situation. If the network is good, the installation can be completed in about 10 minutes, and you will see the log message of successful installation as shown in the figure.
Insert picture description here
After the installation is successful, you can open the Python environment in the terminal, enter the following code, and use TensorFlow to implement the "Hello, TensorFlow" routine.
Insert picture description here
Insert picture description here
After running tf.Session(), a prompt message about the CPU will appear. This is because we directly used the TensorFlow binary file and did not configure the compilation options for the computer hardware used, so the best performance of TensorFlow cannot be exerted. To solve this problem, you can start with source configuration and compile TensorFlow.

2.2 Core concepts The core concepts in TensorFlow.

"Hello, TensorFlow" is not a simple log output, but a calculation graph composed of nodes constructed by the TensorFlow interface. The core concepts in the TensorFlow framework.

2.2.1 Graph

The calculation in TensorFlow can be expressed as a directed graph, or computational graph, in which each operation (operation) will act as a node, the connection between nodes It is called an edge. This calculation diagram is used to describe the calculation process of the data, and is responsible for maintaining and updating the state. Users can use Python, C++, Go, Java and other languages ​​to design this directed graph calculated by data, and can also perform conditional control or loop operations on the distribution of the calculated graph.
As shown in the figure is a calculation diagram of a linear regression model. Each node in this calculation graph describes an arithmetic operation, which can have any number of inputs and outputs. The data flowing in the calculation graph is called tensor, hence the name TensorFlow. The data type of tensor can either be defined in advance or inferred from the structure of the calculation graph. There is no data flow in a special kind of edge. This kind of edge is called dependency control. The function is to execute the target node after the start node is executed. The user can use such an edge for flexible condition control, such as limiting memory usage. The highest peak.
Insert picture description here

2.2.2 Session

The client interacts with the TensorFlow system by creating a session. The session holds and manages all the resources of the TensorFlow program when it is running. One of the main operation functions provided by the session interface is Run(), which takes the output name to be calculated and the operation set that replaces some output node tensors as its parameter input. Most of the use of TensorFlow is to start a session for a graph, and then execute the entire graph or execute separate subgraphs multiple times through the Run() function.

2.2.3 Variable

In most calculations, graphs are executed multiple times, and most tensors will not survive after one execution. However, a variable is a special operation that can return a handle to a variable tensor that is still alive after the graph is executed several times. This handle can be passed to a series of specific operations, such as Assign and AssignAdd (equivalent to +=) to change the tensor referenced. Corresponding to the application of TensorFlow in machine learning, the parameters of the model are generally stored in the tensor referenced by the variables and updated as part of the model training graph.

Guess you like

Origin blog.csdn.net/weixin_45661757/article/details/115284707