当前位置:网站首页>Tensorflow actual combat Google deep learning framework second edition learning summary tensorflow introduction
Tensorflow actual combat Google deep learning framework second edition learning summary tensorflow introduction
2022-06-10 15:23:00 【Easier said than done wangshuailpp】
The content of this paper mainly makes a knowledge summary for the third chapter
summary :TensorFlow The working principle of is divided into calculation model , Data model and operation model .
1.TensorFlow Calculation model - Calculation chart
1.1 Computational graph model
tensorflow A programming system that expresses computation in the form of a computation diagram , One of those tensorflow Each calculation in is a node on the calculation graph , And the edge between nodes describes the dependency between calculations . The following figure is a typical calculation diagram model 
1.2 The calculation chart uses
tensorflow The procedure is generally divided into two stages , The first stage is to define all the calculations in the calculation diagram , In the second stage, the calculation is performed. The default calculation graph can be obtained through the default calculation graph function , The line and surface code demonstrates how to get the default calculation diagram and how to view the calculation diagram :
print(a.grapy is tf.get_default>graph)
In addition to the default calculation chart , Can pass tf.Graph Generate a new calculation chart . Be careful , The tensor on the newly generated computational graph ( It can be understood as data ) And operations are not shared . For example, the final output results of the following code are 0 and 1.
import tensorflow as tf
g1 = tf.Graph()
with g1.as_default():
v = tf.get_variable("v", [1], initializer = tf.zeros_initializer()) # Set the initial value to 0
g2 = tf.Graph()
with g2.as_default():
v = tf.get_variable("v", [1], initializer = tf.ones_initializer()) # Set the initial value to 1
with tf.Session(graph = g1) as sess:
tf.global_variables_initializer().run()
with tf.variable_scope("", reuse=True):
print(sess.run(tf.get_variable("v")))
with tf.Session(graph = g2) as sess:
tf.global_variables_initializer().run()
with tf.variable_scope("", reuse=True):
print(sess.run(tf.get_variable("v")))2.TensorFlow Calculation model - tensor
The tensor is tensorflow Form of management data , All the data are expressed in the form of tensor , Functionally speaking , Tensor can be simply understood as multidimensional data , Zero order tensors represent scalars , It's a number , The first tensor is a vector , That is, a one-dimensional array , The first n The order tensor can be understood as a n For data .
import tensorflow as tf
a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([2.0, 3.0], name="b")
result = a + b
print result
sess = tf.InteractiveSession ()
print(result.eval())
sess.close() The output of the code is Tensor(“add:0”, shape=(2,), dtype=float32)
No result of the addition is output , Just a reference to the result , The structure of the instant tensor . From the structure of the tensor, we can see , The first attribute of the tensor is not only the unique identifier of the tensor , The technical process of tensor is also given , With node:src_output Form gives ,add Is the node name ,0 Indicates the number of output nodes . The second attribute is the dimension of the tensor ,shape(2,) The representation is a one-dimensional array , The length is 2. The third attribute is the type .
Note here that the tensor itself does not store specific numbers , Only through the conversation can we get the specific value .
3.TensorFlow Calculation model - conversation
Session owned and managed tensorflow All resources at program run time , So you need to close the session to help the system reclaim resources after the calculation , Otherwise, there will be a memory leak .tensorflow In general use python Context manager to use sessions , Just put all the calculations in with Internal , When the context manager exits, it will automatically release all resources .
with tf.Session() as sess:
print(sess.run(result))边栏推荐
- Wechat applet returns to the previous page and transfers parameters
- ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解0——整体框架与理论基础知识
- Huawei cloud SRE deterministic O & M introduction
- Day10/11 递归 / 回溯
- [rust daily] first release of mnemos on April 20, 2022
- Li Kou daily question - day 18 -350 Intersection of two data Ⅱ
- 力扣每日一题-第18天-350.两个数据的交集Ⅱ
- Even some people say that ArrayList is twice as large. Today, I will take you to tear up the ArrayList source code
- 3、再遇HandyControl之窗体
- js获取数组中最大值
猜你喜欢

Create a space of local value together. In 2022, China successfully held the "one hundred cities tour · Ningbo Station" for commercial distribution

AEC of the three swordsmen in audio and video processing: the cause of echo generation and the principle of echo cancellation

详解OpenCV的函数filter2D(),并提醒大家它做的运算并不是卷积运算而是相关运算

AutoCAD - set text spacing and line spacing

CVPR 2022 oral | SCI: fast, flexible and robust low light image enhancement

ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解2——IMU初始化

2022 the 15th Nanjing International Industrial Automation Exhibition

Development of stm8s103f single chip microcomputer (1) lighting of LED lamp

二分查找详解

RSA a little bit of thought
随机推荐
点投影到平面上的方法总结
Li Kou daily question - day 18 -350 Intersection of two data Ⅱ
RSA a little bit of thought
Golang []byte 转 File
BigDecimal removes extra 0 at the end
100003 words, take you to decrypt the system architecture under the double 11 and 618 e-commerce promotion scenarios
Fast detection of short text repetition rate
Sanzi chess (implemented in C language)
Interview question details
Kubernetes 1.24: avoid conflicts when assigning IP addresses to services
ORB_SLAM2视觉惯性紧耦合定位技术路线与代码详解1——IMU流型预积分
One-way hash function
Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
TensorFlow实战Google深度学习框架第二版学习总结-TensorFlow安装
Kubernetes 1.24: 避免为 Services 分配 IP 地址时发生冲突
4. Meet panuon again UI. Title bar of silver form
竟然還有人說ArrayList是2倍擴容,今天帶你手撕ArrayList源碼
Wechat applet color gradient
百度开源ICE-BA安装运行总结
The power of insight