Pytorch神经网络所需的编程基础知识
nn.Module类
class AlexNet(nn.Module)
,类AlexNet继承自nn.Module类,详解见:
n.Module类详解——使用Module类来自定义模型
def init(self, name等多参数)
__init__(self)
初始化,详解见:
读懂python中的self
python def init(self, name等多参数), def init(self)
Python 中__init__函数以及参数self
super().init()
super(Class, self).xxx
调用父类的方法, Python 3 可以使用直接使用 super().xxx
代替 super(Class, self).xxx
,详解见:
Python super() 函数
super().__init__()
,继承父类的init初始化方法,详解见:
python中super().init()
view()
view()
作用是将一个多行的Tensor,拼接成一行,起到resize的作用,详见:
Pytorch-view的用法
forward的调用
在使用pytorch的训练模型时,不需要使用forward,只要在实例化一个对象中传入对应的参数就可以自动调用 forward 函数,详见:
pytorch 中的 forward 的使用与解释
nn.Modlue及nn.Linear 源码理解