TensorFlow machine learning installation and configuration (2)

TensorFlow is an artificial intelligence learning system open sourced by Google. Why is it called this name? Tensor means tensor, representing N-dimensional array; Flow means flow, representing computation based on data flow graph. The process of flowing N-dimensional numbers from one end of the flow graph to the other is the process of analysis and processing by the artificial intelligence neural network.
It is said that after Android occupied the mobile terminal, Google open sourced TensorFlow, hoping to occupy the AI ​​side. The feature of TF is that it can support a variety of devices, ranging from GPUs and CPUs to small tablets and mobile phones, which can run TF. And TF is very convenient to use, and you can start running the model with a few lines of code, which makes getting started with neural networks very simple.
This article is the first, and it is the most basic content. The veteran can skip it.
1. Installation of TensorFlow
Before starting to write code, we must first install TensorFlow on the computer. There are two methods here, one is manual command line installation one by one, and the other is batch GUI installation.
First look at the manual installation, we can install TensorFlow and upyter Notebook.
1) Install TensorFlow
On Windows:
Install CPU version: Open the command line in administrator mode, enter the command: pip install tensorflow
Install GPU version: Open the command line in administrator mode, enter the command: pip install tensorflow-gpu
write picture description here
On Linux: The
command is the same as above, if you are using Python3 point A few versions, then the installation command is:
Install the CPU version: Enter the command: pip3 install tensorflow
Install the GPU version: Enter the command: pip3 install tensorflow-gpu
If you are prompted that pip is not installed, mac students can install pip first through the command:
1 Command line input: curlhttps://bootstrap.pypa.io/ez_setup.py-o - | sudo python
2 Command line input:sudo easy_install pip
2) Install Jupyter Notebook
This is an interactive notebook, you can understand it as a more beautiful and concise editor. It is easy to create and share literary program documentation, supporting live code, mathematical equations, visualization and markdown. Generally used for data cleaning and transformation, numerical simulation, statistical modeling, machine learning, etc.
Enter the command: pip install jupyter
The previous method is to manually install one by one. In fact, someone has already helped us to make a large set, and there is no need to manually install one by one. The following describes the batch installation method of the graphical interface:
1) Install Anaconda. What is Anaconda? If you think of TensorFlow as a bazooka, then Anaconda is an arsenal, which contains a variety of scientific computing and machine learning Python tool libraries. After downloading from the official website, install it directly, then open Anaconda, you can see the following page:
write picture description here
2) Click on the Environments in the second line, you can see many toolkits, search for TensorFlow, check it, and then click Apply to proceed Just install it. If you need other toolkits in the future, you can also find them there and check them to install them.
write picture description here
OK, this is the end of the installation tutorial. With jupyter and tensorflow, we can start basic operations.
Second, the basic operations of TensorFlow
Before engaging in neural networks, let us first clarify the basic operations of TensorFlow, that is, addition, subtraction, multiplication and division.
First of all, TensorFlow has several concepts that need to be clarified:
1 Graph: used to represent computing tasks, that is, some operations we have to do.
2 Session: When a session is established, an empty graph will be generated; nodes and edges are added to the session to form a graph, a session can have multiple graphs, and results are obtained by executing these graphs. If you think of each graph as a lathe, the session is a workshop with several lathes used to produce data into results.
3 Tensor: used to represent data, it is our raw material.
4 Variable (Variable): used to record some data and status, is our container.
5 feed and fetch: You can assign values ​​to or get data from arbitrary operations. Equivalent to some shovels, you can manipulate data.
The metaphor of the image is: think of the session as a workshop, and the graph as a lathe, which uses Tensor as the raw material, variables as the container, feed and fetch as the shovel, and the data is processed into our results.
2.1 Create a graph and run a graph:
write picture description here
Let's create a graph and execute it in the session. Don't worry about not understanding it. Every sentence of code will be annotated. As long as there is a programming foundation, it can be OK:
the above is to use TensorFlow to perform the simplest one. Matrix multiplication.
2.2 Create a variable and use the for loop to assign values ​​to the variable.
write picture description here
It can be seen that, except that the variable creation is a little more troublesome and a session must be established to run, other operations are basically the same as ordinary Python.
2.3 Setting the value of placeholder through
feed Sometimes, we do not assign values ​​when declaring variables, and assign values ​​only when calculating. At this time, the feed comes in handy
write picture description here
. Congratulations, you have successfully started TensorFlow~ Do you think Too simple? It seems to have nothing to do with deep learning wool.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325770927&siteId=291194637