探秘最炙手可热的人工智能框架TensorFlow

Coding Alan 7年前 (2018-05-20) 9971次浏览 1个评论 扫描二维码

探秘最炙手可热的人工智能框架TensorFlow

环境搭建可参考Django环境搭建及开发的环境搭建部分,也可参照TensorFlow官网

本文主要内容

TensorFlow的基础知识

  • TensorFlow经典的数据流图
  • TensorFlow的Hello World
  • TensorBoard
  • TensorFlow的操作(Operations)

TensorFlow的使用案例

  • 梯度下降解决线性回归
  • 激活函数(Activation Function)
  • 实现CNN(Convolution Neural Network)卷积神经网络
  • RNN-LSTM循环神经网络

TensorFlow的基础知识

TensorFlow经典的数据流图

探秘最炙手可热的人工智能框架TensorFlow

图中的各个节点是操作(Operation),中间的线是张量(Tensor)

TensorFlow的Hello World

Tensor有以下几种:constant(常量), Variable(变量), placeholder(占位符),SparseTensor(稀疏张量)

TensorBoard

如以下是后面卷积神经网络示例的TensorBoard

探秘最炙手可热的人工智能框架TensorFlow

Playground

TensorFlow的操作(Operations)

探秘最炙手可热的人工智能框架TensorFlow

TensorFlow的使用案例

梯度下降解决线性回归

探秘最炙手可热的人工智能框架TensorFlow

激活函数(Activation Function)

探秘最炙手可热的人工智能框架TensorFlow

深度学习的三大模型:

CNN(Convolution Neural Network)卷积神经网络
RNN(Recurrent Neural Network)循环神经网络
DBN(Deep Belief Network)深度信念网络

实现CNN(Convolution Neural Network)卷积神经网络

探秘最炙手可热的人工智能框架TensorFlow

训练结果如下

RNN-LSTM循环神经网络

探秘最炙手可热的人工智能框架TensorFlow

RNN问题:梯度消失、梯度爆炸

LSTM: Long Short-Term Memory

扩展阅读:Understanding LSTM Networks

LSTM神经元的“三重门”机制

探秘最炙手可热的人工智能框架TensorFlow

PTB数据集:

wget http://www.fit.vutbr.cz/~imikolov/rnnlm/simple-examples.tgz

本例中使用data文件夹下的ptb.test.txt,ptb.train.txt,ptb.valid.txt三个文件

探秘最炙手可热的人工智能框架TensorFlow

utils.py

network.py

train.py

test.py

在Mac上进行一次训练需耗时30多分钟,写这篇文章时训练仍在进行,以下是第二次训练完成后执行test.py的结果,可以看到精确度还是很低的:

True words (1st line) vs. predicted words (2nd line)

stock market is headed many traders were afraid to trust stock prices quoted on the big board <eos> the futures halt was even <unk> by big board floor traders <eos> it <unk> things up said

is market is n’t by of said <unk> to be <eos> prices <eos> at a dollar board <eos> the dollar index that a a in a board in in said the is a that a

Average accuracy: 0.236

 

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. 能问一下运行train的时候Traceback (most recent call last): File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1334, in _do_call return fn(*args) File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1319, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1407, in _call_tf_sessionrun run_metadata)tensorflow.python.framework.errors_impl.AlreadyExistsError: Resource __per_step_5/gradients/rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/BiasAdd/Enter_grad/ArithmeticOptimizer/AddOpsRewrite_Add/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar [[{{node gradients/rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/BiasAdd/Enter_grad/ArithmeticOptimizer/AddOpsRewrite_Add/tmp_var}} = TemporaryVariable[dtype=DT_FLOAT, shape=[2600], var_name="gradients/...dd/tmp_var", _device="/job:localhost/replica:0/task:0/device:CPU:0"](^gradients/rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/BiasAdd_1_grad/BiasAddGrad)]]During handling of the above exception, another exception occurred:Traceback (most recent call last): File "D:/lsc/test/tf/rnn-lstm/train.py", line 105, in model_save_name='train-checkpoint') File "D:/lsc/test/tf/rnn-lstm/train.py", line 80, in train cost, _, current_state = sess.run([m.cost, m.train_op, m.state], feed_dict={m.init_state: current_state}) File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 929, in run run_metadata_ptr) File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1152, in _run feed_dict_tensor, options, run_metadata) File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1328, in _do_run run_metadata) File "C:\Users\hongxing\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1348, in _do_call raise type(e)(node_def, op, message)tensorflow.python.framework.errors_impl.AlreadyExistsError: Resource __per_step_5/gradients/rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/BiasAdd/Enter_grad/ArithmeticOptimizer/AddOpsRewrite_Add/tmp_var/struct tensorflow::TemporaryVariableOp::TmpVar [[{{node gradients/rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/BiasAdd/Enter_grad/ArithmeticOptimizer/AddOpsRewrite_Add/tmp_var}} = TemporaryVariable[dtype=DT_FLOAT, shape=[2600], var_name="gradients/...dd/tmp_var", _device="/job:localhost/replica:0/task:0/device:CPU:0"](^gradients/rnn/while/rnn/multi_rnn_cell/cell_0/lstm_cell/BiasAdd_1_grad/BiasAddGrad)]]他会报这个错误是什么原因呢?
    lowa2019-05-15 21:58 回复