前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tensorflow编程: Variables

tensorflow编程: Variables

作者头像
JNingWei
发布2018-09-28 15:24:04
7230
发布2018-09-28 15:24:04
举报
文章被收录于专栏:JNing的专栏JNing的专栏

Variables

tf.Variable

Properties:

Properties

Usage

Return

Example for Print

w.device

返回 该variable 所在的 device

非Tensor

w.dtype

返回 该variable 的 DType

非Tensor

<dtype: 'float32_ref'>

w.graph

返回 该variable 的 Graph

非Tensor

<tensorflow.python.framework.ops.Graph object at 0x7fb06cdd2210>

w.initial_value

返回 该variable 的 初始值

Tensor

10.0

w.initializer

返回 该variable 的 初始op

非Tensor

(太长了就不放进来了)

w.name

返回 该variable 的 名称

非Tensor

Variable:0

w.op

返回 该variable 的 op

非Tensor

(太长了就不放进来了)

w.shape

返回 该variable 的 shape

非tensor

()

Methods:

Methods

Usage

Return

Example for Print

w.assign_add(10)

返回 该variable 加 10 之后 的 variable

Tensor

20.0

w.assign_sub(10)

返回 该variable 减 10 之后 的 variable

Tensor

10.0

w.assign(100)

返回 重新赋值为 100 之后 的 variable

Tensor

100.0

w.get_shape()

返回 该variable 的 shape

非Tensor

()

w.initialized_value()

返回 该variable 的 初始化值

Tensor

100.0

w.load(200)

将 新值 载入 此variable

200.0

w.read_value()

返回 该variable 的 值

Tensor

200.0

w.set_shape()

重置 该variable 的 shape

()

w.value()

返回 该variable 的 最后一个 快照

Tensor

200.0

代码语言:javascript
复制
# coding=utf-8
import tensorflow as tf

# 新建 variable
w = tf.Variable(initial_value=10., dtype=tf.float32)

sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())

# Properties
print '\nw.device :\n', w.device
print '\nw.dtype :\n', w.dtype
print '\nw.graph :\n', w.graph
print '\nw.initial_value :\n', w.initial_value.eval()
print '\nw.initializer :\n', w.initializer
print '\nw.name :\n', w.name
print '\nw.op :\n', w.op
print '\nw.shape :\n', w.shape

# method
print '\ntf.add(w, 5) :\n', tf.add(w, 5).eval()
print '\nw.assign_add(10) :\n', w.assign_add(10).eval()
print '\nw.assign_sub(10) :\n', w.assign_sub(10).eval()
print '\nw.assign(100) :\n', w.assign(100).eval()
print '\nw.get_shape() :\n', w.get_shape()
print '\nw.initialized_value() :\n', w.initialized_value().eval()
w.load(200)
print '\nw.load(200) :\n', w.eval()
print '\nw.read_value() :\n', w.read_value().eval()
w.set_shape(())
print '\nw.set_shape() :\n', w.shape
print '\nw.value() :\n', w.value().eval()

sess.close()

结果输出:

代码语言:javascript
复制
w.device :


w.dtype :
<dtype: 'float32_ref'>

w.graph :
<tensorflow.python.framework.ops.Graph object at 0x7fb06cdd2210>

w.initial_value :
10.0

w.initializer :
name: "Variable/Assign"
op: "Assign"
input: "Variable"
input: "Variable/initial_value"
(折叠。。。)

w.name :
Variable:0

w.op :
name: "Variable"
op: "VariableV2"
(折叠。。。)

w.shape :
()

tf.add(w, 5) :
15.0

w.assign_add(10) :
20.0

w.assign_sub(10) :
10.0

w.assign(100) :
100.0

w.get_shape() :
()

w.initialized_value() :
100.0

w.load(200) :
200.0

w.read_value() :
200.0

w.set_shape() :
()

w.value() :
200.0

Variable helper functions

tf.global_variables

tf.local_variables

tf.model_variables

tf.trainable_variables

tf.moving_average_variables tf.global_variables_initializer tf.local_variables_initializer tf.variables_initializer tf.is_variable_initialized tf.report_uninitialized_variables tf.assert_variables_initialized tf.assign tf.assign_add tf.assign_sub


Saving and Restoring Variables

tf.train.Saver tf.train.latest_checkpoint tf.train.get_checkpoint_state tf.train.update_checkpoint_state


Sharing Variables

tf.get_variable tf.get_local_variable tf.VariableScope tf.variable_scope tf.variable_op_scope tf.get_variable_scope tf.make_template tf.no_regularizer tf.constant_initializer tf.random_normal_initializer tf.truncated_normal_initializer tf.random_uniform_initializer tf.uniform_unit_scaling_initializer tf.zeros_initializer tf.ones_initializer tf.orthogonal_initializer


Variable Partitioners for Sharding


Sparse Variable Updates


Exporting and Importing Meta Graphs



本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年10月05日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Variables
    • tf.Variable
    • Variable helper functions
      • tf.global_variables
        • tf.local_variables
          • tf.model_variables
            • tf.trainable_variables
            • Saving and Restoring Variables
            • Sharing Variables
            • Variable Partitioners for Sharding
            • Sparse Variable Updates
            • Exporting and Importing Meta Graphs
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档