Tensorflow
第一篇博文吧,打算记录一些tensorflow的使用注意事项
tf.Variable tf.train.Saver
变量初始化:tf.initialize_all_variables( )
weight = tf.Variable(tf.random_normal([784,280]), stddev = 0.5, name = 'w1' )
w2 = tf.Variable(weights.initialized_value(), name = 'w2')
saver = tf.train.Saver( ) saver.save( ) saver.restore( )
tensorflow graph (这一块看了好几遍了都没有看懂)
node - operation ; edge - data operated
tf.Graph
- graph collections
- tf.add_to_collections associate a series of objects with a key
- tf.get_collection (当我们定义 variable 时, 会默认加入到 default variables key )
- tf.Tensor 作为graph 中 传递数据和返回数据存储的类型
- Tensor. get_shape ( ) Tensor.eval( feed_dict = ; sess = )
** v = tf.Variable( )** 向graph 中添加一个operation store a writable tensor value
other methods: assign assign_add
** call tf.train.Optimizer.minimize ** add all operations and tensors to the default graph
return a tf.Operation ( a list of variables)
tensorflow and numpy
tf.convert_to_tensor( ) tensor.eval( )
要对tensor进行操作,需要先启动一个Session,否则,我们无法对一个tensor比如一个tensor常量重新赋值或是做一些判断操作,所以如果将它转化为numpy数组就好处理了。下面一个小程序讲述了将tensor转化为numpy数组,以及又重新还原为tensor:*[https://blog.youkuaiyun.com/ljs_a/article/details/78758116]