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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章