tensflow

tensorflow入门

2019-01-27  本文已影响30人  松鼠的读书笔记

1、TensorFlow express a numeric computation as a graph

Graph nodes are operations which have any number of inputs and outputs

Graph edges are tensors which flow between nodes

tensorflow计算图

2、Variables, Placeholders & Operations

(1)Variables are stateful nodes which output their current value. State is retained across multiple executions of a graph (mostly parameters)

(2)Placeholders are nodes whose value is fed in at execution time (inputs, labels, …)

(3) Mathematical operations:

① MatMul: Multiply two matrix values.

② Add: Add elementwise (with broadcasting).

③ ReLU: Activate with elementwise rectified linear function.

3、Steps of writing and running programs in TensorFlow

(1)创建tensors (variables)

(2)定义tensors之间的操作

(3)初始化tensors

(4)创建会话

(5)运行会话 

示例代码如下:


》First build a graph using variables and placeholders:

创建计算图

》Then deploy the graph onto a session, which is the execution environment:

执行计算图

4、How to train the model ?

(1)Build a graph  创建计算图

(2)Feedforward / Prediction  前向传播 / 预测

(3)Optimization (gradients and train_step operation)  优化

(4)Initialize a session  初始化会话

(5)Train with session.run(train_step, feed_dict)  运行会话,训练模型

代码示例如下:


定义损失 计算梯度 构建训练步骤 训练模型

5、Variables sharing

变量共享

参考资料:斯坦福CS224N深度学习自然语言处理课程

上一篇 下一篇

猜你喜欢

热点阅读