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)>>& ...
随机推荐
- java 获取request参数集
request里有两个方法 request.getParameterMap(); request.getParameterNames(); 我想用这两种方法获取. 1.用request.getPara ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A - Neverending competitions
地址:http://codeforces.com/contest/765/problem/A 题目: A. Neverending competitions time limit per test 2 ...
- 08/27 Django admin相关
一.django-admin的简单回顾: admin: Django的后台数据管理的web版本 1.admin a:models.py - 创建表 b:admin.py - 注册表 admin. ...
- Sybase:解锁
Sybase:解锁 Sql代码: --查询锁表 sp_iqlocks --解除锁定 drop connection[连接序号]
- ubuntu循环登录问题的解决
之前试过几个方法都不行,包括改/etc/profile,startx,删Xauthority文件等,这些都是因为,形象地来说是药不对症,ubuntu循环登录是有很多个问题造成的,前面的这些例子只是针对 ...
- Luogu-3648 [APIO2014]序列分割
Luogu-3648 [APIO2014]序列分割 题目链接 题解: 首先要发现一个重要的性质:分割的顺序是不会影响答案的 证明: 首先对于没有交的两段区间,显然先后顺序改变不会有影响 而对于在同一段 ...
- TeamViewer---Linux远程控制利器
TeamViewer中国官网 TeamViewer用户手册 参考链接一 参考链接二 参考链接三:每天一个linux命令(41):ps命令 简介 TeamViewer是一个远程控制软件,兼容于Micro ...
- Spring -- aop, 用Aspectj进行AOP开发
1. 概要 添加类库:aspectjrt.jar和aspectjweaver.jar 添加aop schema. 定义xml元素:<aop:aspectj-autoproxy> 编写jav ...
- bzoj 2190: [SDOI2008]仪仗队 线性欧拉函数
2190: [SDOI2008]仪仗队 Time Limit: 10 Sec Memory Limit: 259 MB[Submit][Status][Discuss] Description 作为 ...
- Java多线程 - Callable和Future
已知的创建多线程的方法有继承Tread类和实现Runnable方法.此外Java还提供了Callable接口,Callable接口也提供了一个call()方法来做为线程执行体.但是call()方法与r ...