[Explanation for beginners] TensorFlow basic syntax and concept

Basic syntax and concept of TensorFlow

I will try Getting Started With TensorFlow on the official page and explain the points. After understanding this content, it is quick to understand if you do the tutorial of "[Explanation for beginners] TensorFlow tutorial MNIST (for beginners)". I was out of focus).

Reference link

-Installing TensorFlow on Windows was easy even for Python beginners -[Explanation for beginners] TensorFlow tutorial MNIST (for beginners) -Visualize TensorFlow tutorial MNIST (for beginners) with TensorBoard -TensorFlow API memo -[Introduction to TensorBoard] Visualize TensorFlow processing to deepen understanding -[Introduction to TensorBoard: image] TensorFlow Visualize image processing to deepen understanding -[Introduction to TensorBoard: Projector] Make TensorFlow processing look cool -[Explanation for beginners] TensorFlow Tutorial Deep MNIST -Yuki Kashiwagi's facial features to understand TensorFlow [Part 1]

What is TensorFlow?

TensorFlow This is an open source library created for machine learning by Google, which is well known. TensorFlow's ** "Tensor" is simply a multidimensional array ** (a general term, not Google-specific). For more information on Tensor, see Tensors you should know before starting TensorFlow (Addition: To more general topics) The article is great. TensorFlow is a good library for working with Tensor. And we are using CPU and GPU as effectively as possible to optimize for machine learning. For example, if you run the MNIST deep learning tutorial on a 2-core PC, it will almost completely use up the CPU as shown in the figure below. 20.CPU_Full.JPG

Basic syntax and concept of TensorFlow

I will explain the concept while looking at the basic syntax of TensorFlow.

Computational Graph TensorFlow is based on the concept of Computational Graph, and commands are divided into two categories: building and executing Computational Graph.

For example, if you define two constants and output them, it will be as follows in C language (it may be a little different because it is an old memory, but feel it like that. ).

const double node1 = 3.0;
const double node2 = 4.0;
printf("%f, %f", node1, node2);

If you write it in TensorFlow as if it were a normal language, it will be as follows.

node1 = tf.constant(3.0, dtype=tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)

However, what is output above is the result below. The constants 3.0 and 4.0 are not output. This is because the above syntax is ** "Building a Computational Graph" **. ** Think of "Computational Graph" as a processing plan that considers parallelism and processing order **.

Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32)

To actually output the constant value, you need to ** "Run Computational Graph" ** with the following syntax.

sess = tf.Session()
print(sess.run([node1, node2]))

Now, finally 3.0 and 4.0 are output as below.

[3.0, 4.0]

It looks like this when illustrated. 30.ComputationalGraph01.JPG

Summary

Compared with normal language processing, it looks like the figure below. It is characterized by two steps of construction (planning) and execution by Computational Graph. If it is a process that simply registers records in the DB, normal language processing that uses only one CPU is simpler, but if it is complicated and has a large parallelization merit such as machine learning or deep learning, TensorFlow would be more appropriate. In my experience, Spark, Hadoop, SAP HANA, etc. can be processed in parallel in a form similar to Computational Graph. 30.ComputationalGraph02.JPG

Recommended Posts

[Explanation for beginners] TensorFlow basic syntax and concept
[Explanation for beginners] TensorFlow tutorial MNIST (for beginners)
[Explanation for beginners] TensorFlow tutorial Deep MNIST
Implementation and explanation using XGBoost for beginners
Basic Python grammar for beginners
[Explanation for beginners] Introduction to convolution processing (explained in TensorFlow)
[Explanation for beginners] Introduction to pooling processing (explained in TensorFlow)
How to learn TensorFlow for liberal arts and Python beginners
TensorFlow MNIST For ML Beginners Translation
Basic syntax notes for shell script
TensorFlow Tutorial MNIST For ML Beginners
TensorFlow Tutorial -MNIST For ML Beginners
[Explanation for beginners] OpenCV face detection mechanism and practice (detect MultiScale)
Elasticsearch installation and basic operation for ubuntu
Linux operation for beginners Basic command summary
Supplementary notes for TensorFlow MNIST For ML Beginners
Beginners read "Introduction to TensorFlow 2.0 for Experts"
Differences between Ruby and Python (basic syntax)
SublimeText2 and SublimeLinter --Syntax check for Python3--
Causal reasoning and causal search with Python (for beginners)
[Python / Chrome] Basic settings and operations for scraping
Basic principles of image recognition technology (for beginners)
Conducting the TensorFlow MNIST For ML Beginners Tutorial
Installing TensorFlow on Windows Easy for Python beginners
Basic story of inheritance in Python (for beginners)
Roadmap for beginners
Rock-paper-scissors poi in Python for beginners (answers and explanations)
Organizing basic procedures for data analysis and statistical processing (4)
I tried the MNIST tutorial for beginners of tensorflow.
Beginners! Basic Linux commands and how to use them!
Caffe Model Zoo for beginners [Age and gender classification]
Organizing basic procedures for data analysis and statistical processing (2)
[Introduction for beginners] Reading and writing Python CSV files
Python Exercise for Beginners # 1 [Basic Data Types / If Statements]
[For beginners] Learn basic Python grammar for free in 5 hours!
Python # How to check type and type for super beginners
Learn about python's print function and strings for beginners.
Explanation of package tools and commands for Linux OS
[For beginners] Django Frequently used commands and reference collection