1 人工智能、机器学习与深度学习简介
增强式学习,借助定义 Actions、States、Rewards 的方式不断训练机器循序渐进,学会执行某项任务的算法。常用算法有Q-Learning、TD(Temporal Difference)、Sarsa
总结的比较好的一个机器学习框架
2 深度学习原理
主要从神经传导原理导入,以 Multilayer Perceptron (MLP)为例
2.1 神经传导原理
是我看过的比较销魂的神经网络模型
1×2 = 1×3 × 3×2 + 1*2
2.2 MLP
MINIST
train时,梯度更新,mini-batch,每次读取一批数据进行反向传播算法训练(多样本求均值)
损失函数
one-hot encoding
梯度更新过程
一个样本,算一次梯度,就有一个新的w1和w2。mini-batch,多个样本,多个w1和w2求均值。
3 TensorFlow与Keras介绍
TensorFlow:低级深度学习链接库,Brain Team 开发,15年11月公开源码
Keras:高级深度学习链接库
3.1 TensorFlow架构图
可以跨平台使用,Raspberry Pi树莓派
具备分布式计算能力
前端语言,对python支持最好
高级API,Keras、TF-Learn、TF-Slim、TF-Layer
3.2 TensorFlow简介
1)Tensor(张量)
零维的 Tensor 是标量,1维的是向量,2维以上的是矩阵
2)Flow(数据流)
去陌生的城市,不会当地的语言,最好的方式,画一张图告诉司机你的目的地
computational graph
Node:代表运算(圆圈)
edge:张量的数据流
3.3 TensorFlow程序设计模式
核心是computational graph
分为:建立 computational graph 和建立Session 执行 computational graph
Session(会话)的作用是在客户端和执行设备之间建立连接。有了这个连接,就可以将computational graph在各个不同的设备中执行,后续任何与设备之间的数据传输都必须通过Session来进行,并且最后获得执行后的结果。
tf.Variable()构造函数需要变量的初始值,它可以是任何类型和形状的Tensor(张量)。 初始值定义变量的类型和形状。 施工后,变量的类型和形状是固定的。 该值可以使用其中一种赋值方式进行更改。
placeholder, 译为占位符,官方说法:”TensorFlow provides a placeholder operation that must be fed with data on execution.” 即必须在执行时feed值。
placeholder 实例通常用来为算法的实际输入值作占位符。例如,在MNIST例子中,定义输入和输出:
x = tf.placeholder(tf.float32, [None, 784])
#表示成员类型float32, [None, 784]是tensor的shape, None表示第一维是任意数量,784表示第二维是784维
y_ = tf.placeholder(tf.float32, [None, 10])
举个 的例子
import tensorflow as tf
import numpy as np
W =tf.Variable(tf.random_normal([3,2]),name='w') #random_normal,从正态分布中输出随机值。
b =tf.Variable(tf.random_normal([3,2]),name='b')
X = tf.placeholder("float",[None,3],name='X')# placeholder,实例通常用来为算法的实际输入值作占位符
y = tf.nn.sigmoid(tf.matmul(X,W)+b,'y') #激活函数
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run(init)
X_array = np.array([[0.4,0.2,0.4],
[0.3,0.4,0.5],
[0.3,-0.4,0.5]])
(_b,_W,_X,_y) = sess.run((b,W,X,y),feed_dict={X:X_array})
3.4 Keras介绍
Keras是一个model-level的深度学习链接库,Keras必须配合backend engine 后端引擎(Theano、TensorFlow)进行计算(底层的Tensor计算)。
3.5 Keras程序设计模式
蛋糕架+加蛋糕
1) 蛋糕架
model = Sequential()
2) 加蛋糕
- add input and hidden layer in the model
- add output layer in the model
3.6 Keras与TensorFlow比较
4 在Windows中安装TensorFlow 与 Keras
- 安装Anaconda
- 建立TensorFlow的Anaconda虚拟环境
- 启动Anaconda虚拟环境,在虚拟环境中安装TensorFlow与Keras
- 启动Jupyter Notebook
5 在Linux Ubuntu中安装TensorFlow 与 Keras
- 安装Anaconda
- 安装TensorFlow与Keras
- 启动Jupyter Notebook
本地远程访问Ubuntu16.04.3服务器上的Jupyter notebook
6 Keras MNIST手写数字识别数据集
【Keras-MLP】MNIST
1、2、3、4节
7 Keras MNIST多层感知器识别手写数字
【Keras-MLP】MNIST
5、6、7、8节
8 Keras CNN MNIST
9 Keras CIFAR-10图像识别数据集
参考
【1】TensorFlow中文社区
【2】tensorflow 生成随机数 tf.random_normal 和 tf.random_uniform 和 tf.truncated_normal 和 tf.random_shuffle
【3】TensorFlow函数——tf.variable( )
【4】tensorflow框架学习(一)placeholder 与variable
【5】 《TensorFlow+Keras深度学习人工智能实践应用》 林大贵
声明:拍摄图片均来源《TensorFlow+Keras深度学习人工智能实践应用》 林大贵版,引用、转载请注明出处,谢谢