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)>>& ...
随机推荐
- c# 图片加密解密的实例代码
c# 图片加密解密的实例代码. 代码: using System; using System.Collections.Generic; using System.Text; using System. ...
- 小知识:pyhon的作用域
http://www.cnblogs.com/wupeiqi/p/5649402.html 五句话搞定JavaScript作用域 从JavaScript == pyhon 作用域几乎一致 __ ...
- django联合查询
假设A表的主键aid作为B表的外键,A表有属性name,那么想查询B表中name为abc的元素就可以这样写: B.objects.all().filter(aid__name = 'abc') __真 ...
- 关于 ActionBar、ToolBar、StatusBar 的开发经验整理
一.ActionBar.ToolBar概述 1.1 ActionBar 1.2 ToolBar 1.3 StatusBar StatusBar 是一个半透明阴影,View 可以伸展到其后面. 1.4 ...
- iOS导入高德地图出现缺失armv7--"Undefined symbols for architecture armv7"
在已有项目中使用pod导入高德地图,报了以下错误: ld: warning: directory not found for option '-L/Users/paul/iOS/yun-hui-yi/ ...
- linux 基础知识总结
1. 查看目录文件命令: 查看以f开头的文件:ll f* 查看/usr/local目录下的文件:ll /usr/local 按最后的修改的时间顺序,列出:ll -t */f* ...
- bat脚本相关
前期准备: 将要执行的脚本名字生成到一个txt文件 首先进入dos运行程序的目录下:输入dir *.jmx /B>FileScript.txt 采用dir *.jmx>list.txt 如 ...
- 08/27 Django admin相关
一.django-admin的简单回顾: admin: Django的后台数据管理的web版本 1.admin a:models.py - 创建表 b:admin.py - 注册表 admin. ...
- java object 转为 json
JSONObject jsonObject=JSONObject.fromObject(map) 执行到这的时候没有任何反应的原因及解决办法 http://blog.csdn.net/tjcyjd/a ...
- jsp基础知识点——思维导图
如图 思维导图图片链接 http://www.edrawsoft.cn/viewer/public/s/0b8cd083478732 有道云笔记图片链接 http://note.youdao.com/ ...