PyTorch with Examples
CS231n Lecture 6 Deep Learning Hardware and Software
Learning PyTorch with Examples - Tutorials
Tensor
Tensor 手动构建网络
1 | import torch |
Autograd
Autograd 自动微分
1 | import torch |
torch.nn
nn 调用内置模型
1 | import torch |
torch.optim
optimizer 使用优化器
1 | import torch |
torch.nn.Module
nn.Module 自定义模型
A PyTorch Module is a neural net layer; Modules can contain weights or other modules.
基于nn.Module模块可自定义NN网络(层);自定义时可用 ModuleList 添加多个网络层;
自定义的网络可与内置网络层通过 Sequential 容器进一步组合。
1 | import torch |
3 ways of creating a neural network in PyTorch nn.Module
, nn.Sequential
, nn.ModuleList
When should I use nn.ModuleList and when should I use nn.Sequential?
In nn.Sequential, the nn.Module
stored inside are connected in a cascaded way, it has a forward() method.
nn.ModuleList does not have a forward() method, there is no connection between the nn.Module
that it stores.
nn.ModuleList is just a Python list with some enhancement: Module’s parameters are discoverable for optimizer.
DataLoader
DataLoader(torch.utils.data) 数据分批(mini-batch)、重排(shuffle)、多线程
1 | import torch |