深度学习模型
本项目讲述了深度学习中的结构、模型和技巧,使用的深度学习框架是 TensorFlow 和 PyTorch,代码和图文都以 Jupyter Notebook 的形式编写。
传统机器学习
- 感知器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 逻辑回归(二分类器) [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- Softmax 回归(多分类器) [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
多层感知器
- 多层感知器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 带有 Dropout 的多层感知器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 带有 Batch Normalization 的多层感知器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 手写反向传播的多层感知器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
卷积神经网络
基本
- 卷积神经网络 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 使用 He 初始化的卷积神经网络 [PyTorch: GitHub | Nbviewer]
概念
全卷积
数据集介绍
数据集 | 中文名称 | 样本数 | 图像尺寸 | 官方网站 |
---|---|---|---|---|
MNIST | 手写数字数据集 | 训练集 60000,测试集 10000 | (28, 28) | MNIST |
CIFAR-10 | 加拿大高等研究院-10 | 训练集 50000,测试集 10000 | (32, 32) | CIFAR-10 |
SVHN | 街景门牌号 | 训练集 73257,测试集 26032,额外 531131 | 尺寸不一,裁剪后 (32, 32) | SVHN |
CelebA | 名人面部属性数据集 | 202599 | 尺寸不一,图像宽度超过 200 | CelebA |
Quickdraw | 快速涂鸦数据集 | 5000 万 | 原始尺寸是 (256, 256),裁剪后为 (32, 32) | Quickdraw |
模型搭建与训练
数据集 | 模型 | 任务 | 地址 | 测试集准确率 |
---|---|---|---|---|
CIFAR-10 | LeNet-5 | 图像分类 | PyTorch: GitHub | Nbviewer | 61.70% |
CIFAR-10 | Network in Network | 图像分类 | PyTorch: GitHub | Nbviewer | 70.67% |
CIFAR-10 | AlexNet | 图像分类 | PyTorch: GitHub | Nbviewer | 73.68% |
CIFAR-10 | VGG-16 | 图像分类 | PyTorch: GitHub | Nbviewer | 76.31% |
CIFAR-10 | VGG-19 | 图像分类 | PyTorch: GitHub | Nbviewer | 74.56% |
CIFAR-10 | DenseNet-121 | 图像分类 | PyTorch: GitHub | Nbviewer | 74.97% |
CIFAR-10 | ResNet-101 | 图像分类 | PyTorch: GitHub | Nbviewer | 75.15% |
MNIST | ResNet 残差模块练习 | 数字分类 | PyTorch: GitHub | Nbviewer | 97.91% |
MNIST | LeNet-5 | 数字分类 | PyTorch: GitHub | Nbviewer | 98.47% |
MNIST | ResNet-18 | 数字分类 | PyTorch: GitHub | Nbviewer | 99.06% |
MNIST | ResNet-34 | 数字分类 | PyTorch: GitHub | Nbviewer | 99.04% |
MNIST | ResNet-50 | 数字分类 | PyTorch: GitHub | Nbviewer | 98.39% |
MNIST | DenseNet-121 | 数字分类 | PyTorch: GitHub | Nbviewer | 98.95% |
CelebA | VGG-16 | 性别分类 | PyTorch: GitHub | Nbviewer | 95.48% |
CelebA | ResNet-18 | 性别分类 | PyTorch: GitHub | Nbviewer | 97.38% |
CelebA | ResNet-34 | 性别分类 | PyTorch: GitHub | Nbviewer | 97.56% |
CelebA | ResNet-50 | 性别分类 | PyTorch: GitHub | Nbviewer | 97.40% |
CelebA | ResNet-101 | 性别分类 | PyTorch: GitHub | Nbviewer | 97.52% |
CelebA | ResNet-152 | 性别分类 | PyTorch: GitHub | Nbviewer | |
Quickdraw | LeNet | 图像分类 | PyTorch: GitHub | Nbviewer | 88.94% |
Quickdraw | ResNet-34 | 图像分类 | PyTorch: GitHub | Nbviewer | 97.73% |
规范化层
- Network in Network 训练 CIFAR-10 时,批规范化层(BatchNorm)放在激活函数前后的差异 [PyTorch: GitHub | Nbviewer]
- Network in Network 训练 CIFAR-10 时使用 Filter Response Normalization [PyTorch: GitHub | Nbviewer]
度量学习
自编码器
全连接自编码器
- 自编码器(MNIST) [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 自编码器(MNIST)+ Scikit-Learn 随机森林分类器 [TensorFlow 1: GitHub | Nbviewer]
卷积自编码器
- 反卷积 / 转置卷积实现的卷积自编码器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 具有反卷积和连续Jaccard距离的卷积自动编码器 [PyTorch: GitHub | Nbviewer]
- 转置卷积实现的卷积自编码器(没有使用池化操作) [PyTorch: GitHub | Nbviewer]
- 最近邻插值实现的卷积自编码器 [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 在 CelebA 上训练的最近邻插值卷积自编码器 [PyTorch: GitHub | Nbviewer]
- 在 Quickdraw 上训练的最近邻插值卷积自编码器 [PyTorch: GitHub | Nbviewer]
变分自动编码器
条件变分自动编码器
- 条件变分自动编码器(重建损失中带标签) [PyTorch: GitHub | Nbviewer]
- 条件变分自动编码器(重建损失中没有标签) [PyTorch: GitHub | Nbviewer]
- 卷积条件变分自动编码器(重建损失中带标签) [PyTorch: GitHub | Nbviewer]
- 卷积条件变分自动编码器(重建损失中没有标签) [PyTorch: GitHub | Nbviewer]
生成对抗网络 (GANs)
- 在 MNIST 上训练的全连接 GAN [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 在 MNIST 上训练的全连接 Wasserstein GAN [PyTorch: GitHub | Nbviewer]
- 在 MNIST 上训练的卷积 GAN [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 在 MNIST 上使用标签平滑训练的卷积 GAN [TensorFlow 1: GitHub | Nbviewer] [PyTorch: GitHub | Nbviewer]
- 在 MNIST 上训练的卷积 Wasserstein GAN [PyTorch: GitHub | Nbviewer]
图神经网络 (GNNs)
- Most Basic Graph Neural Network with Gaussian Filter on MNIST
[PyTorch: GitHub | Nbviewer] - Basic Graph Neural Network with Edge Prediction on MNIST
[PyTorch: GitHub | Nbviewer] - Basic Graph Neural Network with Spectral Graph Convolution on MNIST
[PyTorch: GitHub | Nbviewer]
递归神经网络 (RNNs)
多对一:情感分析、分类
- 一个简单的单层RNN(IMDB)[PyTorch: GitHub | Nbviewer]
- 一个简单的单层RNN,带有打包序列,用于忽略填充字符(IMDB) [PyTorch: GitHub | Nbviewer]
- 带有长短期记忆(LSTM)的RNN(IMDB) [PyTorch: GitHub | Nbviewer]
- 带有长短期记忆(LSTM)的RNN,使用预训练 GloVe 词向量 [PyTorch: GitHub | Nbviewer]
- 带有长短期记忆(LSTM)的RNN,训练 CSV 格式的数据集(IMDB)[PyTorch: GitHub | Nbviewer]
- 带有门控单元(GRU)的RNN(IMDB) [PyTorch: GitHub | Nbviewer]
- 多层双向 GRU(IMDB) [PyTorch: GitHub | Nbviewer]
- 多层双向 LSTM 训练 CSV 格式的数据集(AG News)[PyTorch: GitHub | Nbviewer]
- 多层双向 LSTM 训练 CSV 格式的数据集(Yelp Review Polarity) [PyTorch: GitHub | Nbviewer]
- 多层双向 LSTM 训练 CSV 格式的数据集(Amazon Review Polarity) [PyTorch: GitHub | Nbviewer]
多对多 / 序列对序列
序数回归
- 序数回归 CNN -- CORAL w. ResNet34(AFAD-Lite) [PyTorch: GitHub | Nbviewer]
- 序数回归 CNN -- Niu et al. 2016 w. ResNet34(AFAD-Lite) [PyTorch: GitHub | Nbviewer]
- 序数回归 CNN -- Beckham and Pal 2016 w. ResNet34(AFAD-Lite) [PyTorch: GitHub | Nbviewer]
技巧和窍门
- 循环学习率 [PyTorch: GitHub | Nbviewer]
- 动态增加 Batch Size 来模拟退火(在 CIFAR-10 上训练 AlexNet) [PyTorch: GitHub | Nbviewer]
- 梯度裁剪(在 MNIST 上训练 MLP) [PyTorch: GitHub | Nbviewer]
迁移学习
PyTorch 工作流程和机制
自定义数据集
- 自定义 DataLoader 读取 PNG 文件 [PyTorch: GitHub | Nbviewer]
- 使用 torch.utils.data 加载自定义数据集 -- CSV 文件转换为 HDF5 格式 [PyTorch: GitHub | Nbviewer]
- 使用 torch.utils.data 加载自定义数据集 -- 来自 CelebA 的面部图像 [PyTorch: GitHub | Nbviewer]
- 使用 torch.utils.data 加载自定义数据集 -- 来自 Quickdraw 的手绘图像 [PyTorch: GitHub | Nbviewer]
- 使用 torch.utils.data 加载自定义数据集 -- 来自街景门牌号数据集(SVHN)的图像 [PyTorch: GitHub | Nbviewer]
- 使用 torch.utils.data 加载自定义数据集 -- 亚洲面部数据集 (AFAD) [PyTorch: GitHub | Nbviewer]
- 使用 torch.utils.data 加载自定义数据集 -- 照片年代追溯数据集(Dating Historical Color Images) [PyTorch: GitHub | Nbviewer]
训练和预处理
- 生成训练集和验证集 [PyTorch: GitHub | Nbviewer]
- 在 DataLoader 中使用固定内存(pin_memory)技术 [PyTorch: GitHub | Nbviewer]
- 标准化图像(Standardization) [PyTorch: GitHub | Nbviewer]
- 使用 torchvision 进行图像变换(数据增强) [PyTorch: GitHub | Nbviewer]
- 在自己的文本数据上训练 Char-RNN [PyTorch: GitHub | Nbviewer]
- 在自己的文本数据集上使用 LSTM 进行情感分类 [PyTorch: GitHub | Nbviewer]
并行计算
其他
- Sequential API 和 Hook 技术 [PyTorch: GitHub | Nbviewer]
- 同层权值共享 [PyTorch: GitHub | Nbviewer]
- 使用 Matplotlib 在 Jupyter Notebook 中绘制实时训练曲线 [PyTorch: GitHub | Nbviewer]
自动求梯度(Autograd)
TensorFlow 工作流程和机制
自定义数据集
- 使用 NumPy npz 格式打包小批量图像数据集 [TensorFlow 1: GitHub | Nbviewer]
- 使用 HDF5 格式保存小批量图像数据集 [TensorFlow 1: GitHub | Nbviewer]
- 使用输入管道在 TFRecords 文件中读取数据 [TensorFlow 1: GitHub | Nbviewer]
- 使用队列运行器(Queue Runners)从硬盘中直接读取图像 [TensorFlow 1: GitHub | Nbviewer]
- 使用 TensorFlow 数据集 API [TensorFlow 1: GitHub | Nbviewer]