tensorflow_cookbook:Ch 1: Getting Started with TensorFlow_(3,4)
来源:互联网 发布:iphone7垃圾清理软件 编辑:程序博客网 时间:2024/06/05 16:04
Variables and Placeholders
Here we initialize a simple placeholder for a piece of data. We then feed a random number into an identity function. If viewed in Tensorboard, the following graph will be created.
#03_placeholders.py# Placeholders#----------------------------------## This function introduces how to # use placeholders in Tensorflowimport numpy as npimport tensorflow as tffrom tensorflow.python.framework import opsops.reset_default_graph()# Using Placeholderssess = tf.Session()x = tf.placeholder(tf.float32, shape=(4, 4))y = tf.identity(x)rand_array = np.random.rand(4, 4)#####merged = tf.merge_all_summaries()merged = tf.summary.merge_all()#writer = tf.train.SummaryWriter("/tmp/variable_logs", sess.graph_def)writer = tf.summary.FileWriter("/tmp/variable_logs", sess.graph)####writer.close()print(sess.run(y, feed_dict={x: rand_array}))
原代码会报错
AttributeError: module 'tensorflow' has no attribute 'merge_all_summaries'AttributeError: module 'tensorflow.python.training.training' has no attribute 'SummaryWriter'
修改后结果
[[ 0.66682321 0.3293488 0.5245204 0.53379935] [ 0.07488234 0.10959593 0.68837297 0.17703928] [ 0.35069257 0.77648026 0.27833292 0.44115242] [ 0.76638317 0.15466152 0.22070079 0.94068062]]
Working with Matrices
Placeholder for future purposes.
# 04_matrices.py#Matrices and Matrix Operations#----------------------------------## This function introduces various ways to create# matrices and how to use them in Tensorflowimport numpy as npimport tensorflow as tffrom tensorflow.python.framework import opsops.reset_default_graph()# Declaring matricessess = tf.Session()# Declaring matrices# Identity matrixidentity_matrix = tf.diag([1.0,1.0,1.0])print(sess.run(identity_matrix))# 2x3 random norm matrixA = tf.truncated_normal([2,3])print(sess.run(A))# 2x3 constant matrixB = tf.fill([2,3], 5.0)print(sess.run(B))# 3x2 random uniform matrixC = tf.random_uniform([3,2])print(sess.run(C))print(sess.run(C)) # Note that we are reinitializing, hence the new random variabels# Create matrix from np arrayD = tf.convert_to_tensor(np.array([[1., 2., 3.], [-3., -7., -1.], [0., 5., -2.]]))print(sess.run(D))# Matrix addition/subtractionprint(sess.run(A+B))print(sess.run(B-B))# Matrix Multiplicationprint(sess.run(tf.matmul(B, identity_matrix)))# Matrix Transposeprint(sess.run(tf.transpose(C))) # Again, new random variables# Matrix Determinantprint(sess.run(tf.matrix_determinant(D)))# Matrix Inverseprint(sess.run(tf.matrix_inverse(D)))# Cholesky Decompositionprint(sess.run(tf.cholesky(identity_matrix)))# Eigenvalues and Eigenvectorsprint(sess.run(tf.self_adjoint_eig(D)))
[[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]][[ 0.4898375 -0.65810621 0.20719798] [-0.45387158 -0.72594666 0.2478656 ]][[ 5. 5. 5.] [ 5. 5. 5.]][[ 0.37838769 0.72760344] [ 0.2227149 0.2249614 ] [ 0.73352134 0.32676136]][[ 0.90364814 0.73233008] [ 0.61350799 0.37857103] [ 0.41849363 0.42342687]][[ 1. 2. 3.] [-3. -7. -1.] [ 0. 5. -2.]][[ 3.90597057 4.19510365 6.0628376 ] [ 4.86557484 6.02541924 3.63600206]][[ 0. 0. 0.] [ 0. 0. 0.]][[ 5. 5. 5.] [ 5. 5. 5.]][[ 0.04690075 0.34524703 0.48222351] [ 0.15054452 0.74442649 0.36477065]]-38.0[[-0.5 -0.5 -0.5 ] [ 0.15789474 0.05263158 0.21052632] [ 0.39473684 0.13157895 0.02631579]][[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]](array([-10.65907521, -0.22750691, 2.88658212]), array([[ 0.21749542, 0.63250104, -0.74339638], [ 0.84526515, 0.2587998 , 0.46749277], [-0.4880805 , 0.73004459, 0.47834331]]))
阅读全文
0 0
- tensorflow_cookbook:Ch 1: Getting Started with TensorFlow_(3,4)
- tensorflow_cookbook:Ch 1: Getting Started with TensorFlow_(1,2)
- tensorflow_cookbook:Ch 1: Getting Started with TensorFlow_(5,6)
- tensorflow_cookbook:Ch 1: Getting Started with TensorFlow_(7)Data Source Information
- tensorflow_cookbook:Ch 1: Getting Started with TensorFlow(8)08_Additional_Resources
- Tutorials:Getting Started with jQuery---4
- Tutorials:Getting Started with jQuery---3
- Chapter 3: Getting Started With Devops
- [转]Getting Started with Hadoop, Part 1
- Getting Started with Hadoop, Part 1
- [转]Getting Started with Hadoop, Part 1
- [转]Getting Started with Hadoop, Part 1
- [转]Getting Started with Hadoop, Part 1
- Tutorials:Getting Started with jQuery---1
- Getting Started with D3 [Part 1]
- windbg - Getting Started with WinDBG - Part 1
- TensorFlow Note 1 : Getting Started With TensorFlow
- Getting Started with Smartphone
- 企业必须考虑的关于大数据架构的6大问题
- 微信小程序 页面跳转和数据传递实例详解
- Vue基础之事件处理器
- Makefile & Android.mk文件
- Android Drawable 那些不为人知的高效用法
- tensorflow_cookbook:Ch 1: Getting Started with TensorFlow_(3,4)
- ios新手开发入门项目-登陆界面
- 前端之vue.js分页插件
- React组件之间的传值
- linux下的文件权限问题
- tomcat服务器配置注意的问题
- 激活设备管理器权限,防止被卸载
- 【mysql】添加列
- rsync + lsyncd 文件实时同步/备份