本书首先介绍了深度学习相关的理论和主流的深度学习框架,然后从Caffe 深度学习框架为切入点,介绍了Caffe 的安装、配置、编译和接口等运行环境,剖析Caffe 网络模型的构成要素和常用的层类型和Solver 方法。通过LeNet 网络模型的Mnist 手写实例介绍其样本训练和识别过程,进一步详细解读了AlexNet、VGGNet、GoogLeNet、Siamese 和SqueezeNet 网络模型,并给出了这些模型基于Caffe 的训练实战方法。然后,本书解读了利用深度学习进行目标定位的经典网络模型:FCN、R-CNN、Fast-RCNN、Faster-RCNN 和SSD,并进行目标定位Caffe 实战。本书的最后,从著名的Kaggle 网站引入了两个经典的实战项目,并进行了有针对性的原始数据分析、网络模型设计和Caffe 训练策略实践,以求带给读者从问题提出到利用Caffe 求解的完整工程经历,从而使读者能尽快掌握Caffe 框架的使用技巧和实战经验。针对Caffe 和深度学习领域的初学者,本书是一本不可多得的参考资料。本书的内容既有易懂的理论背景,又有丰富的应用实践,是深度学习初学者的指导手册,也可作为深度学习相关领域工程师和爱好者的参考用书。 第1 章 绪论................................................................................................................................1 1.1 引言...............................................................................................................................1 1.2 人工智能的发展历程....................................................................................................2 1.3 机器学习及相关技术....................................................................................................4 1.3.1 学习形式分类.....................................................................................................4 1.3.2 学习方法分类.....................................................................................................5 1.3.3 机器学习的相关技术.........................................................................................7 1.4 国内外研究现状............................................................................................................8 1.4.1 国外研究现状.....................................................................................................8 1.4.2 国内研究现状.....................................................................................................9 第2 章 深度学习.......................................................................................................................11 2.1 神经网络模型..............................................................................................................11 2.1.1 人脑视觉机理...................................................................................................11 2.1.2 生物神经.......................................................................................................13 2.1.3 人工神经网络...................................................................................................15 2.2 BP 神经网络................................................................................................................18 2.2.1 BP 神经.........................................................................................................18 2.2.2 BP 神经网络构成.............................................................................................19 2.2.3 正向传播...........................................................................................................21 2.2.4 反向传播...........................................................................................................21 2.3 卷积神经网络..............................................................................................................24 2.3.1 卷积神经网络的历史.......................................................................................25 2.3.2 卷积神经网络的网络结构...............................................................................26 2.3.3 局部感知...........................................................................................................27 2.3.4 参数共享...........................................................................................................28 2.3.5 多卷积核...........................................................................................................28 2.3.6 池化(Pooling)...............................................................................................29 2.4 深度学习框架..............................................................................................................30 2.4.1 Caffe ..................................................................................................................30 2.4.2 Torch ..................................................................................................................31 2.4.3 Keras..................................................................................................................32 2.4.4 MXNet ...............................................................................................................32 2.4.5 TensorFlow ........................................................................................................33 2.4.6 CNTK ................................................................................................................33 2.4.7 Theano ...............................................................................................................34 第3 章 Caffe 简介及其安装配置.............................................................................................36 3.1 Caffe 是什么................................................................................................................36 3.1.1 Caffe 的特点......................................................................................................38 3.1.2 Caffe 的架构......................................................................................................38 3.2 Caffe 的安装环境........................................................................................................39 3.2.1 Caffe 的硬件环境..............................................................................................39 3.2.2 Caffe 的软件环境..............................................................................................43 3.2.3 Caffe 的依赖库..................................................................................................44 3.2.4 Caffe 开发环境的安装......................................................................................46 3.3 Caffe 接口....................................................................................................................52 3.3.1 Caffe Python 接口.............................................................................................52 3.3.2 Caffe MATLAB 接口........................................................................................55 3.3.3 Caffe 命令行接口..............................................................................................56 第4 章 Caffe 网络定义.............................................................................................................58 4.1 Caffe 模型要素............................................................................................................58 4.1.1 网络模型...........................................................................................................58 4.1.2 参数配置...........................................................................................................62 4.2 Google Protobuf 结构化数据.......................................................................................63 4.3 Caffe 数据库................................................................................................................65 4.3.1 LevelDB.............................................................................................................65 4.3.2 LMDB................................................................................................................66 4.3.3 HDF5 .................................................................................................................66 4.4 Caffe Net.......................................................................................................................66 4.5 Caffe Blob.....................................................................................................................68 4.6 Caffe Layer ...................................................................................................................70 4.6.1 Data Layers........................................................................................................71 4.6.2 Convolution Layers............................................................................................75 4.6.3 Pooling Layers ...................................................................................................76 4.6.4 InnerProduct Layers...........................................................................................77 4.6.5 ReLU Layers......................................................................................................78 4.6.6 Sigmoid Layers..................................................................................................79 4.6.7 LRN Layers .......................................................................................................79 4.6.8 Dropout Layers ..................................................................................................80 4.6.9 SoftmaxWithLoss Layers...................................................................................80 4.6.10 Softmax Layers................................................................................................81 4.6.11 Accuracy Layers ..............................................................................................81 4.7 Caffe Solver ..................................................................................................................82 Solver 方法....................................................................................................................83 第5 章 LeNet 模型....................................................................................................................88 5.1 LeNet 模型简介...........................................................................................................88 5.2 LeNet 模型解读...........................................................................................................89 5.3 Caffe 环境LeNet 模型.................................................................................................91 5.3.1 mnist 实例详解.................................................................................................91 5.3.2 mnist 手写测试...............................................................................................103 5.3.3 mnist 样本字库的图片转换............................................................................106 第6 章 AlexNet 模型..............................................................................................................107 6.1 AlexNet 模型介绍......................................................................................................107 6.2 AlexNet 模型解读......................................................................................................108 6.3 AlexNet 模型特点......................................................................................................111 6.4 Caffe 环境AlexNet 模型训练...................................................................................112 6.4.1 数据准备.........................................................................................................112 6.4.2 其他支持文件.................................................................................................113 6.4.3 图片预处理.....................................................................................................113 6.4.4 ImageNet 数据集介绍.....................................................................................113 6.4.5 ImageNet 图片介绍.........................................................................................115 6.4.6 ImageNet 模型训练.........................................................................................115 6.4.7 Caffe 的AlexNet 模型与论文的不同............................................................124 6.4.8 ImageNet 模型测试.........................................................................................124 第7 章 GoogLeNet 模型........................................................................................................126 7.1 GoogLeNet 模型简介................................................................................................126 7.1.1 背景和动机.....................................................................................................127 7.1.2 Inception 结构.................................................................................................127 7.2 GoogLeNet 模型解读................................................................................................129 7.2.1 GoogLeNet 模型结构......................................................................................129 7.2.2 GoogLeNet 模型特点......................................................................................134 7.3 GoogLeNet 模型的Caffe 实现..................................................................................135 第8 章 VGGNet 模型.............................................................................................................146 8.1 VGGNet 网络模型.....................................................................................................146 8.1.1 VGGNet 模型介绍..........................................................................................146 8.1.2 VGGNet 模型特点..........................................................................................147 8.1.3 VGGNet 模型解读..........................................................................................147 8.2 VGGNet 网络训练.....................................................................................................149 8.2.1 VGGNet 训练参数设置..................................................................................149 8.2.2 Multi-Scale 训练.............................................................................................149 8.2.3 测试.................................................................................................................150 8.2.4 部署.................................................................................................................150 8.3 VGGNet 模型分类实验.............................................................................................150 8.3.1 Single-scale 对比.............................................................................................150 8.3.2 Multi-scale 对比..............................................................................................151 8.3.3 模型融合.........................................................................................................152 8.4 VGGNet 网络结构.....................................................................................................153 第9 章 Siamese 模型.............................................................................................................158 9.1 Siamese 网络模型......................................................................................................159 9.1.1 Siamese 模型原理...........................................................................................159 9.1.2 Siamese 模型实现...........................................................................................160 9.2 Siamese 网络训练......................................................................................................165 9.2.1 数据准备.........................................................................................................165 9.2.2 生成side..........................................................................................................165 9.2.3 对比损失函数.................................................................................................166 9.2.4 定义solver.......................................................................................................166 9.2.5 网络训练.........................................................................................................166 第10 章 SqueezeNet 模型....................................................................................................168 10.1 SqueezeNet 网络模型..............................................................................................168 10.1.1 SqueezeNet 模型原理...................................................................................168 10.1.2 Fire Module ...................................................................................................169 10.1.3 SqueezeNet 模型结构...................................................................................170 10.1.4 SqueezeNet 模型特点...................................................................................171 10.2 SqueezeNet 网络实现..............................................................................................172 第11 章 FCN 模型..................................................................................................................177 11.1 FCN 模型简介..........................................................................................................177 11.2 FCN 的特点和使用场景..........................................................................................178 11.3 Caffe FCN 解读........................................................................................................179 11.3.1 FCN 模型训练准备.......................................................................................180 11.3.1 FCN 模型训练...............................................................................................183 第12 章 R-CNN 模型.............................................................................................................196 12.1 R-CNN 模型简介.....................................................................................................196 12.2 R-CNN 的特点和使用场景.....................................................................................197 12.3 Caffe R-CNN 解读...................................................................................................198 12.3.1 R-CNN 模型训练准备..................................................................................198 12.3.2 R-CNN 模型训练..........................................................................................201 第13 章 Fast-RCNN 模型.....................................................................................................217 13.1 Fast-RCNN 模型简介..............................................................................................217 13.2 Fast-RCNN 的特点和使用场景..............................................................................218 13.3 Caffe Fast-RCNN 解读............................................................................................220 13.3.1 Fast-RCNN 模型训练准备...........................................................................220 13.3.2 Fast-RCNN 模型训练...................................................................................222 第14 章 Faster-RCNN 模型..................................................................................................239 14.1 Faster-RCNN 模型简介...........................................................................................239 14.2 Faster-RCNN 的特点和使用场景...........................................................................241 14.3 Caffe Faster-RCNN 解读.........................................................................................242 14.3.1 Faster-RCNN 模型训练准备........................................................................242 14.3.2 Faster-RCNN 模型训练................................................................................244 第15 章 SSD 模型..................................................................................................................264 15.1 SSD 模型简介..........................................................................................................264 15.2 SSD 的特点和使用场景..........................................................................................266 15.3 Caffe SSD 解读........................................................................................................267 15.3.1 SSD 模型训练准备.......................................................................................267 15.3.2 SSD 模型训练...............................................................................................268 第16 章 Kaggle 项目实践:人脸特征检测..........................................................................290 16.1 项目简介..................................................................................................................290 16.2 赛题和数据..............................................................................................................291 16.3 Caffe 训练和测试数据库.........................................................................................293 16.3.1 数据库生成...................................................................................................293 16.3.2 网络对比.......................................................................................................295 16.3.3 网络一...........................................................................................................296 16.3.4 网络二...........................................................................................................300 16.3.5 Python 人脸特征预测程序...........................................................................306 第17 章 Kaggle 项目实践:猫狗分类检测..........................................................................311 17.1 项目简介..................................................................................................................311 17.2 赛题和数据..............................................................................................................312 17.3 Caffe 训练和测试数据库.........................................................................................312 17.3.1 数据库生成...................................................................................................312 17.3.2 Caffe 实现......................................................................................................316 17.3.3 CatdogNet 训练.............................................................................................328 17.3.4 CatdogNet 模型验证.....................................................................................332 |