tensorflow(1)

来源:互联网 发布:软件开发工资待遇 编辑:程序博客网 时间:2024/06/16 01:45
[原文]
The central unit of data in TensorFlow is the tensor. A tensor consists of a set of primitive values shaped into an array of any number of dimensions. A tensor's rank is its number of dimensions. Here are some examples of tensors:
3 # a rank 0 tensor; this is a scalar with shape []
[1., 2., 3.] # a rank 1 tensor; this is a vector with shape [3]
[[1., 2., 3.], [4., 5., 6.]] # a rank 2 tensor; a matrix with shape [2, 3]
[[[1., 2., 3.]], [[7., 8., 9.]]] # a rank 3 tensor with shape [2, 1, 3]
[解释]
tensor:张量
0级张量(标量):例如,3 - shape []
1级张量(一维,向量):例如,[1., 2., 3.] - shape [3]
2级张量(二维,矩阵):例如,[[1., 2., 3.], [4., 5., 6.]] - shape [2, 3]
3级张量(三维):例如,[[[1., 2., 3.]], [[7., 8., 9.]]] - shape [2, 1, 3]
[参考]http://wiki.jikexueyuan.com/project/tensorflow-zh/resources/dims_types.html
[例]two_nodes.py
import tensorflow as tf
node1 = tf.constant(3.0, dtype=tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)
sess = tf.Session()
print(sess.run([node1, node2]))
node3 = tf.add(node1, node2)
print("node3:", node3)
print("sess.run(node3):", sess.run(node3))
file_writer = tf.summary.FileWriter('/tmp/tensorflow/two_nodes/logs', sess.graph)

运行:
sudo python two_nodes.py
sudo tensorboard --logdir /tmp/tensorflow/two_nodes/logs/
打开浏览器,输入:http://127.0.0.1:6006
点GRAPHS,可以看到计算图。
原创粉丝点击