tensorflow笔记03

  1. 1. Tensorflow TensorBoard数据流图可视化
  2. 2. 指定CPU和GPU设备

Tensorflow TensorBoard数据流图可视化

tf.summary.scalar()

tf.summary.histogram()

tf.summary.Filewriterr:

​ writer = tf.summary.Filewriter(“summary_dir”,sess.graph)

将摘要和图形写入summary_dir中

在控制台输入tensorboard —logdir=summary_dir, 在浏览器中输入他给的地址即可。

拿上一篇的代码举例

浏览器中显示

指定CPU和GPU设备

1
2
3
4
5
6
...
#/cpu:0 使用第0个cpu
tf.device('/cpu:0')
#/gpu:0 使用第0个gpu
tf.device('/gpu:0')
...

配置显示使用设备

1
2
3
4
5
#设定配置
tf.ConfigProto()
#参数:
log_device_placement = True #显示使用设备
allow_soft_placement = True #TensorFlow自动设定当前使用设备,若手动设定GPU来算,但是不支持,会自动调到CPU

使用配置:

1
2
3
4
5
6
7
8
9
import tensorflow as tf

with tf.device('/gpu:0'):
v1 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v1')
v2 = tf.constant([1.0, 2.0, 3.0], shape=[3], name='v2')
sumV12 = v1 + v2

with tf.Session(config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=True)) as sess:
print(sess.run(sumV12))

使用CPU0运行

使用GPU0运行