- TensorFlow Machine Learning Projects
- Ankit Jain Armando Fandango Amita Kapoor
- 245字
- 2021-06-10 19:15:28
Obtaining variables with the tf.get_variable()
If a variable is defined with a name that has already been used for another variable, then an exception is thrown by TensorFlow. The tf.get_variable() function makes it convenient and safe to create a variable in place of using the tf.Variable() function. The tf.get_variable() function returns a variable that has been defined with a given name. If the variable with the given name does not exist, then it will create the variable with the specified initializer and shape.
Consider the following example:
w = tf.get_variable(name='w',shape=[1],dtype=tf.float32,initializer=[.3])
b = tf.get_variable(name='b',shape=[1],dtype=tf.float32,initializer=[-.3])
The initializer can either be a list of values or another tensor. An initializer can also be one of the built-in initializers. Some of these are as follows:
- tf.ones_initializer
- tf.constant_initializer
- tf.zeros_initializer
- tf.truncated_normal_initializer
- tf.random_normal_initializer
- tf.random_uniform_initializer
- tf.uniform_unit_scaling_initializer
- tf.orthogonal_initializer
The tf.get_variable() function only returns the global variables when the code is run across multiple machines in distributed TensorFlow. The local variables can be retrieved by using the tf.get_local_variable() function.
Now that we have learned how to define tensors, constants, operations, placeholders, and variables, let's learn about the next level of abstraction in TensorFlow that combines these basic elements to form a basic unit of computation: the computation graph.
- 大學(xué)計(jì)算機(jī)信息技術(shù)導(dǎo)論
- Hands-On Intelligent Agents with OpenAI Gym
- 大學(xué)計(jì)算機(jī)基礎(chǔ):基礎(chǔ)理論篇
- 21小時(shí)學(xué)通AutoCAD
- Learning Apache Cassandra(Second Edition)
- 網(wǎng)絡(luò)綜合布線技術(shù)
- 數(shù)據(jù)庫原理與應(yīng)用技術(shù)
- WordPress Theme Development Beginner's Guide(Third Edition)
- 完全掌握AutoCAD 2008中文版:綜合篇
- 運(yùn)動控制器與交流伺服系統(tǒng)的調(diào)試和應(yīng)用
- 控制系統(tǒng)計(jì)算機(jī)仿真
- 氣動系統(tǒng)裝調(diào)與PLC控制
- 機(jī)器人人工智能
- 嵌入式GUI開發(fā)設(shè)計(jì)
- 智能鼠原理與制作(進(jìn)階篇)