tensorflow 学习笔记 2

Github上有个学习tensorflow的git

https://github.com/nfmcclure/tensorflow_cookbook

内容完整,买了中文版,但是却很多细节,所以还是直接看github原版好了。电子书是ipynb格式的,ubuntu看起来很容易。


从第一个example开始:

电子书

https://github.com/nfmcclure/tensorflow_cookbook/tree/master/01_Introduction/02_Creating_and_Using_Tensors

代码链接:

https://github.com/nfmcclure/tensorflow_cookbook/blob/master/01_Introduction/02_Creating_and_Using_Tensors/02_tensors.py

代码比较短,贴一下好了,对照相关部分的电子书和tensorboard的输出还是能加强一些理解的


# Tensors
  #----------------------------------
  #
  # This function introduces various ways to create
  # tensors in TensorFlow
   
  import tensorflow as tf
  from tensorflow.python.frameworkimport ops
  ops.reset_default_graph()
   
  # Introduce tensors in tf
   
  # Get graph handle
  sess = tf.Session()
   
  my_tensor = tf.zeros([1,20])
   
  # Declare a variable
  my_var = tf.Variable(tf.zeros([1,20]))
   
  # Different kinds of variables
  row_dim = 2
  col_dim = 3
   
  # Zero initialized variable
  zero_var = tf.Variable(tf.zeros([row_dim, col_dim]))
   
  # One initialized variable
  ones_var = tf.Variable(tf.ones([row_dim, col_dim]))
   
  # shaped like other variable
  sess.run(zero_var.initializer)
  sess.run(ones_var.initializer)
  zero_similar = tf.Variable(tf.zeros_like(zero_var))
  ones_similar = tf.Variable(tf.ones_like(ones_var))
   
  sess.run(ones_similar.initializer)
  sess.run(zero_similar.initializer)
   
  # Fill shape with a constant
  fill_var = tf.Variable(tf.fill([row_dim, col_dim],-1))
   
  # Create a variable from a constant
  const_var = tf.Variable(tf.constant([8,6, 7, 5, 3, 0, 9]))
  # This can also be used to fill an array:
  const_fill_var = tf.Variable(tf.constant(-1,shape=[row_dim, col_dim]))
   
  # Sequence generation
  linear_var = tf.Variable(tf.linspace(start=0.0,stop=1.0,num=3))# Generates [0.0, 0.5, 1.0] includes the end
   
  sequence_var = tf.Variable(tf.range(start=6,limit=15,delta=3))# Generates [6, 9, 12] doesn't include the end
   
  # Random Numbers
   
  # Random Normal
  rnorm_var = tf.random_normal([row_dim, col_dim],mean=0.0,stddev=1.0)
   
  # Add summaries to tensorboard
  merged = tf.summary.merge_all()
   
  # Initialize graph writer:
   
  writer = tf.summary.FileWriter("/tmp/variable_logs",graph=sess.graph)
   
  # Initialize operation
  initialize_op = tf.global_variables_initializer()
   
  # Run initialization of variable
  sess.run(initialize_op)

在贴个tensorboard的graph:


如果点击一个具体的变量,会看到与语句的关系,比如

tf.Variable(tf.zeros([1,20]))

对应的就是:


所以很简单的一个理解就是tensorflow框架对tensor做了运算,然后通过tensorboard可以直观的观察到。


一些额外的学习资料:

# Additional Resources

###Official Resources:

 - [TensorFlow Python API](https://www.tensorflow.org/api_docs/python/)
 - [TensorFlow on Github](https://github.com/tensorflow/tensorflow)
 - [TensorFlow Tutorials](https://www.tensorflow.org/tutorials/)
 - [Udacity Deep Learning Class](https://www.udacity.com/course/deep-learning--ud730)
 - [TensorFlow Playground](http://playground.tensorflow.org/)

###Github Tutorials and Examples:

 - [Tutorials by pkmital](https://github.com/pkmital/tensorflow_tutorials)
 - [Tutorials by nlintz](https://github.com/nlintz/TensorFlow-Tutorials)
 - [Examples by americdamien](https://github.com/aymericdamien/TensorFlow-Examples)
 - [TensorFlow Workshop by amygdala](https://github.com/amygdala/tensorflow-workshop)

###Deep Learning Resources

 - [Efficient Back Prop by Yann LeCun, et. al.](http://yann.lecun.com/exdb/publis/pdf/lecun-98b.pdf)
 - [Online Deep Learning Book, MIT Press](http://www.deeplearningbook.org/)
 - [An Overview of Gradient Descent Algorithms by Sebastian Ruder](http://sebastianruder.com/optimizing-gradient-descent/)
 - [Stochastic Optimization by John Duchi, et. al.](http://www.jmlr.org/papers/volume12/duchi11a/duchi11a.pdf)
 - [ADADELTA Method by Matthew Zeiler](http://arxiv.org/abs/1212.5701)
 - [A Friendly Introduction to Cross-Entropy Loss by Rob DiPietro](http://rdipietro.github.io/friendly-intro-to-cross-entropy-loss/)


###Additional Resources

 - [A Curated List of Dedicated TensorFlow Resources](https://github.com/jtoy/awesome-tensorflow/)

###Arxiv Papers

 - [TensorFlow: Large-Scale Machine Learning on Heterogeneous Distributed Systems](http://arxiv.org/abs/1603.04467)
 - [TensorFlow: A system for large-scale machine learning](http://arxiv.org/abs/1605.08695)
 - [Distributed TensorFlow with MPI](https://arxiv.org/abs/1603.02339)
 - [Comparative Study of Deep Learning Software Frameworks](https://arxiv.org/abs/1511.06435)
 - [Wide & Deep Learning for Recommender Systems](https://arxiv.org/abs/1606.07792)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值