tensorflow-1.x-cookbook 读书笔记

本文是关于 《TensorFlow 1.x Deep Learning Cookbook》 的读书笔记。


Hello world in TensorFlow

1. 设置 tensorflow 输出日志等级

1
2
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

2. TensorFlow 与设备

TensorFlow allows you to use specific devices (CPU/GPU) with different objects of the computation graph using with tf.device().


Working with constants, variables, and placeholders

3. Constants 和 Variables 的存储方式

Constants are stored in the computation graph definition; they are loaded every time the graph is loaded. In other words, they are memory expensive. Variables, on the other hand, are stored separately; they can exist on the parameter server.

4. 设置全局 seed

When there are large numbers of random tensors in use, we can set the seed for all randomly generated tensors using tf.set_random_seed(); the following command sets the seed for random tensors for all sessions as 54: tf.set_random_seed(54)

5. 以某种分布初始化 Variable

1
2
3
rand_t = tf.random_uniform([50,50], 0, 10, seed=0)
t_a = tf.Variable(rand_t)
t_b = tf.Variable(rand_t)

6. 将 Variable 作常量使用以优化内存 (Constant 存储在 graph 中,Variable 不是)

1
t_large = tf.Variable(large_array, trainable = False)

Performing matrix manipulations using TensorFlow

7. elementwise operations

All arithmetic operations of matrices like add, sub, div, multiply (elementwise multiplication), mod, and cross require that the two tensor matrices should be of the same data type.

Invoking CPU/GPU devices

8. TensorFlow naming CPU and GPU devices

TensorFlow names the supported devices as “/device:CPU:0” (or “/cpu:0”) for the CPU devices and “/device:GPU:I” (or “/gpu:I”) for the ith GPU device.


文章作者: taosean
文章链接: https://taosean.github.io/2018/11/14/tensorflow-1-x-cookbook/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 taosean's 学习之旅