TensorFlow之编程模式(2)

主要编程模式有:

(1)命令式编程   ——   Torch

(2)符号式编程   ——   TensorFlow

 

命令式编程:

易理解,命令语句基本没优化:C,Java,C++,Python

 

符号式编程:

涉及较多的嵌入和优化,运行速度有同比提升

例如:

1 import tensorflow as tf
2 
3 a = tf.constant(2)
4 b = tf.constant(3)
5 c = tf.multiply(a, b)
6 d = tf.add(c, 1)
7 
8 with tf.Session() as sess:
9     print (sess.run(d))

 

数据流图之图的基本构成

A.Tensor(张量);    B.Operation(操作)

 

TensorFlow的基础模型:

数据模型————Tensor(张量)

计算模型————Graph(图)

运行模型————Session(会话)

 

TensorFlow程序的流程:

1.定义算法的计算图(Graph)结构;

2.使用会话(Session)执行计算。

posted on 2018-09-26 22:18  qiuqiu365  阅读(94)  评论(0编辑  收藏  举报