pytorch中的网络结构
==首先先给出一些python面向对象的一些基础知识==
子类中初始化父类的相关问题
pytorch.nn.module
current layer
Container
torch.nn.Sequential
A sequential container.
Modules will be added to it in the order they are passed in the constructor. Alternatively, an ordered dict of modules can also be passed in.
1 | # Example of using Sequential |
parameters
module 保存所有需要计算的参数
自己在设计网络时,要通过nn.Parameter()
加入module的优化器管理
1 | class MyLiner(nn.Module): |
modules
1 | modules |
GPU
1 | device = torch.device('cuda') |
save and load
save
1 | cn = MyNet() |
load
1 | cn = MyNet() |
train/test
1 | cn = cn.eval()#转换成测试状态 |
了解基本知识之后,以下从构建自己网络的思路开始讲述
mynet
https://blog.csdn.net/qq_27825451/article/details/90550890
https://blog.csdn.net/qq_27825451/article/details/90705328
貌似是需要自己实验forward过程
常用的网络模块
Flatten
1 | class Flatten(nn.Module ): |