本文是关于 《TensorFlow 1.x Deep Learning Cookbook》 的读书笔记。
Hello world in TensorFlow
1. 设置 tensorflow 输出日志等级
1 | import os |
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 | rand_t = tf.random_uniform([50,50], 0, 10, seed=0) |
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.