tensorflow_1

install

1
pip install tensorflow

显示tensorflow的版本

1
2
import tensorflow as tf
tf.__version__

##

tf.constant 定义常量
tf.Variable 定义变量
tf.placeholder 占位符,用于填充数据

  • 定义一个矩阵

  • sigmoid

Tensorboard

  1. 把计算过程用tf.name_scope包装起来
  2. 使用tf.summary.FileWriter输出到目标文件夹
  3. 启动Tensorboard

如果一个op中只有直接的赋值,那么这个op不会显示在Tensorboard中

1
tensorboard --logdir=/test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import tensorflow as tf
import os

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

if __name__ == '__main__':
const_A = tf.constant(10, name = 'const_A', dtype = tf.int64)

const_B = tf.constant(20, name = 'const_B', dtype = tf.int64)

placeholder_C = tf.placeholder(dtype = tf.int64)

with tf.name_scope('Add'):
_sum = const_A + const_B

with tf.Session() as session:
session.run(tf.global_variables_initializer())

const_sum = session.run(_sum)
print(const_sum)

train_writer = tf.summary.FileWriter('/test', session.graph)
train_writer.close()

Reference

1.https://dotblogs.com.tw/shaynling/2017/11/14/173025

2.https://www.tensorflow.org/api_docs/python/tf/matmul