tf随笔-5
# -*- coding: utf-8 -*-
import tensorflow as tf
w1=tf.Variable(tf.random_normal([2,6],stddev=1))
w2=tf.Variable(tf.random_normal([6,1],stddev=1))
x=tf.placeholder(dtype=tf.float32,shape=(4,2),name="input")
h=tf.matmul(x,w1)
y=tf.matmul(h,w2)
init_op=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
print sess.run(y,feed_dict={x:[[5.2,2.9],[3.9,1.1],[3.9,5.2],[6.1,9.2]]})
数据需要通过字典输入
# Launch the graph in a session.
with tf.Session() as sess:
# Run the variable initializer.
sess.run(w.initializer)
# ...you now can run ops that use the value of 'w'...
#global_variables_initializer()to add an Op to the graph that initializes all the variables. You then run that Op after launching the graph.Add an Op to initialize global variables.
init_op = tf.global_variables_initializer()
# Launch the graph in a session.
with tf.Session() as sess:
# Run the Op that initializes global variables.
sess.run(init_op)
# ...you can now run any Op that uses variable values...
tf.Variable
_init__(
initial_value=None,
trainable=True,
collections=None,
validate_shape=True,
caching_device=None,
name=None,
variable_def=None,
dtype=None,
expected_shape=None,
import_scope=None
)
Creates a new variable with value initial_value.
The new variable is added to the graph collections listed in collections, which defaults to [GraphKeys.GLOBAL_VARIABLES].
If trainable is True the variable is also added to the graph collection GraphKeys.TRAINABLE_VARIABLES.
This constructor creates both a variable Op and an assign Op to set the variable to its initial value.
Args:
initial_value: ATensor, or Python object convertible to aTensor, which is the initial value for the Variable. The initial value must have a shape specified unlessvalidate_shapeis set to False. Can also be a callable with no argument that returns the initial value when called. In that case,dtypemust be specified. (Note that initializer functions from init_ops.py must first be bound to a shape before being used here.)trainable: IfTrue, the default, also adds the variable to the graph collectionGraphKeys.TRAINABLE_VARIABLES. This collection is used as the default list of variables to use by theOptimizerclasses.collections: List of graph collections keys. The new variable is added to these collections. Defaults to[GraphKeys.GLOBAL_VARIABLES].validate_shape: IfFalse, allows the variable to be initialized with a value of unknown shape. IfTrue, the default, the shape ofinitial_valuemust be known.caching_device: Optional device string describing where the Variable should be cached for reading. Defaults to the Variable's device. If notNone, caches on another device. Typical use is to cache on the device where the Ops using the Variable reside, to deduplicate copying throughSwitchand other conditional statements.name: Optional name for the variable. Defaults to'Variable'and gets uniquified automatically.variable_def:VariableDefprotocol buffer. If notNone, recreates the Variable object with its contents, referencing the variable's nodes in the graph, which must already exist. The graph is not changed.variable_defand the other arguments are mutually exclusive.dtype: If set, initial_value will be converted to the given type. IfNone, either the datatype will be kept (ifinitial_valueis a Tensor), orconvert_to_tensorwill decide.expected_shape: A TensorShape. If set, initial_value is expected to have this shape.import_scope: Optionalstring. Name scope to add to theVariable.Only used when initializing from protocol buffer.
Raises:
ValueError: If bothvariable_defand initial_value are specified.ValueError: If the initial value is not specified, or does not have a shape andvalidate_shapeisTrue.
tf随笔-5的更多相关文章
- TF随笔-13
import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with ...
- TF随笔-11
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import tensorflow as tf my_var=tf.Variable(0.) step=t ...
- TF随笔-10
#!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constan ...
- TF随笔-9
计算累加 #!/usr/bin/env python2 # -*- coding: utf-8 -*-"""Created on Mon Jul 24 08:25:41 ...
- TF随笔-8
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Jul 10 09:35:04 201 ...
- TF随笔-7
求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]])>> ...
- tf随笔-6
import tensorflow as tfx=tf.constant([-0.2,0.5,43.98,-23.1,26.58])y=tf.clip_by_value(x,1e-10,1.0)ses ...
- TF随笔-4
>>> import tensorflow as tf>>> a=tf.constant([[1,2],[3,4]])>>> b=tf.const ...
- TF随笔-3
>>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>& ...
随机推荐
- ruby underscore
“examScore".underscore : exam_score "ExamScore".underscore: exam_score
- PL/SQL编程—游标
一.游标的相关概念: 定义: 游标它是一个服务器端的存储区,这个区域提供给用户使用,在这个区域里 存储的是用户通过一个查询语句得到的结果集,用户通过控制这个游标区域当中 的指针 来提取游标中的数据,然 ...
- Codeforces Round #396 (Div. 2) C. Mahmoud and a Message
地址:http://codeforces.com/contest/766/problem/C 题目: C. Mahmoud and a Message time limit per test 2 se ...
- 如何自定义echarts 线性图的选择事件
最近在做公司的数据大盘,要用到图表显示,echarts研二的时候有用过,我就决定用它了. 这里用到一个可以同时显示多条曲线的line-charts,基本样子如下: 看到这个画红色圈圈的地方了吗??? ...
- UIScrollView监听静止的数种情况
1.直接通过block -(void)testInBlock { //通过block监听 [UIView animateWithDuration:1.0 animations:^{ self.scro ...
- 【Java并发】Java中的原子操作类
综述 JDK从1.5开始提供了java.util.concurrent.atomic包. 通过包中的原子操作类能够线程安全地更新一个变量. 包含4种类型的原子更新方式:基本类型.数组.引用.对象中字段 ...
- [Android]自定义控件LoadMoreRecyclerView
RecyclerView是加强版的ListView,用于在有限的窗口中展示大量的数据,而LoadMoreRecyclerView则是为RecyclerView增加了加载更多的功能,先来看效果: 三种加 ...
- IntelliJ IDEA 2017 创建SpringBoot项目, 及.jar没有主清单属性解决办法
1. 创建项目: File >> New >> Spring Initializr 选好 SDK, 及 依赖包(比如 Web >> Web ) . 需要使用 ...
- 20 个 OpenSSH 最佳安全实践
来源:https://linux.cn/article-9394-1.html OpenSSH 是 SSH 协议的一个实现.一般通过 scp 或 sftp 用于远程登录.备份.远程文件传输等功能.SS ...
- cf780c
C. Andryush ...