当前位置:网站首页>Usage of tf.variable() function in tensorflow
Usage of tf.variable() function in tensorflow
2022-07-26 03:21:00 【phac123】
reference
tensorflow And tf.Variable() function
sketch
tf.Variable() The function is used to create variables (Variable), A variable is a special tensor (), It can be any shape and type of tensor .
The syntax format is as follows :
tf.Variable.init(initial_value, trainable=True,
collections=None, validate_shape=True, name=None))
Be careful : When starting the diagram ( Before the operation ), All variables must be clearly defined . Variables are often used to store and update parameters , In the process of calculating the chart, its value will be saved until the end of the program , This formally distinguishes general tensors . General Tensorflow In the process of operation, the tensor just flows through the calculation diagram , Will not be preserved ; Related operations involving variables must pass session Session control .
Particular attention : stay tensorflow The definition and initialization of variables in are separate .
Initialize variable : Used to tf.initialize_all_variables() function , But in 2017 year 3 month 2 After number , This function is no longer used , use tf.global_variables_initializer() replace tf.initialize_all_variables()
tf.global_variables_initializer() Used to initialize all variables ;w.initializer Used to initialize a single variable .
Besides : You can also use tf.get_variable () Function to define variables . In essence ,tf.Variable() Is the real definition variable , and tf.get_variable() Is to get variables , The main design purpose is to share variables , But if you can't get it, it's equivalent to newly defined variables .
Besides , Use tf.Variable when , If a naming conflict is detected , The system will take care of itself . Use tf.get_variable() when , The system will not handle conflicts , It's a mistake
Besides, besides , Use tf.Variable() when , If duplicate names are detected , The system will automatically handle , The processing method is generally to add "_n". However ,tf.get_variable() If a duplicate name conflict is found, an error will be reported directly .
example
Use tf.Variable() Create variables
import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()
w = tf.Variable([6,8,6]) # Create variables w
print(w) # Look at the shape, It's not worth it .
with tf.Session() as sess:
sess.run(w.initializer) # Initialize variable
print(sess.run(w)) # Look at the value of the variable
Output :
''' <tf.Variable 'Variable:0' shape=(3,) dtype=int32_ref> [6 8 6] '''
tf.get_variable() And tf.Variable()
import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()
import tensorflow as tf
V1 = tf.Variable([1,2,3],name="V1")
V2 = tf.Variable([2,3,4],name="V1")
V3 = tf.Variable([3,4,5],name="V1_1")
print("V1:",V1.name)
print("V2:",V2.name)
print("V3:",V3.name)
Output :
''' V1: V1:0 V2: V1_1:0 V3: V1_1_1:0 '''
Summary
- Generally, parameters are used initial_value And name That's enough
- tf.get_variable() And tf.Variable() Are used to define variables
边栏推荐
- 离线数据仓库从0到1-阶段一资源购买配置
- 78. 子集
- JVM memory model parsing
- URDF 语法详解
- What are you interviewing for in a big factory? It's worth watching (I)
- Execution process behind shell commands
- ES6 set and map
- QT notes - Q_ Q and Q_ D learning
- Illustration leetcode - 5. Longest palindrome substring (difficulty: medium)
- Alibaba Sentinel - cluster traffic control
猜你喜欢

离线数据仓库从0到1-阶段一资源购买配置

Hcip day 8 notes sorting (OSPF routing control, Appendix E, anti ring, shortest path calculation, republication))

Illustration leetcode - 5. Longest palindrome substring (difficulty: medium)

Course notes of single chip microcomputer principle and interface technology for migrant workers majoring in electronic information engineering

实现一个方法,找出数组中的第k大和第m大的数字相加之和

TCP experimental verification

LoRa无线网关如何快速实现端到云的传输

Why did Mr. Cao, a productionist in the field of high-end tea, choose Ruifeng L6 max?

Unknown-Aware Object Detection:Learning What You Don’t Know from Videos in the Wild(CVPR 2022)

canvas——绘制文本——饼图的修改
随机推荐
【创建交互式 Dice Roller 应用】
2022-07-21 study notes of group 4 self-cultivation class (every day)
URDF 语法详解
QT notes - Q_ Q and Q_ D learning
What are you interviewing for in a big factory? It's worth watching (I)
What's good for starting a business with 10000 yuan? Is we media OK?
Pit trodden when copying list: shallow copy and deep copy
ENVI_ Idl: create HDF5 file and write data (take writing GeoTIFF file to HDF file as an example) + detailed parsing
YOLOv3: An Incremental Improvement
Managing databases in a hybrid cloud: eight key considerations
Looking at the next step of BAIC bluevale through the 8billion fund-raising, product upgrading and building core capabilities are the key words
Leetcode · daily question · sword finger offer | | 115. reconstruction sequence · topological sorting
MPLS基础实验配置
Canvas -- drawing of rectangle -- making of histogram
【无标题】
【尤里复裂人】带你轻松理解——深拷贝和浅拷贝
snownlp库各功能及用法
论文精读-YOLOv1:You Only Look Once:Unified, Real-Time Object Detection
canvas——心电图的设计,以及如何清理画布
What are the methods of array sorting in JS