我正在浏览Udacity的 with pytorch课程的深度学习介绍教师的神经网络部分说:“在初始方法中,我们需要致电超级,我们需要这样做,因为那时Pytorch将知道注册所有不同的层和操作,如果您不这样做,能够跟踪您添加到网络中的内容,并且它将无法使用”。您能否详细说明并说明这里的超级关键字的作用到底是什么?
此外,Jupyter笔记本电脑说了以下有关超级使用的使用,
class Network(nn.Module):
在这里,我们从 nn.module
继承。与
super().__ init __()
这创建了一个跟踪体系结构
并提供许多有用的方法和属性。这是强制性的
从 nn.module
继承时
网络。班级的名称本身可以是任何东西。
I am going through Udacity's Intro To Deep Learning with Pytorch course In the Neural Network part the instructor says that "in the init method, we need to call super, we need to do that because then PyTorch will know to register all the different layers and operation, if you don't do this part it wont be able to track the things that you are adding to your network and it wont work". Could you kindly elaborate and explain what exactly is the role of super keyword here and what does nn.Module inherits which helps in "keeping track" of changes.
Further the Jupyter notebooks says the following about use of super,
class Network(nn.Module):
Here we're inheriting from nn.Module
. Combined with
super().__init__()
this creates a class that tracks the architecture
and provides a lot of useful methods and attributes. It is mandatory
to inherit from nn.Module
when you're creating a class for your
network. The name of the class itself can be anything.
发布评论
评论(1)
类网络(nn.module)
表示您定义了网络
类,该类从nn.module
(>)继承了所有方法和属性网络
是子类,nn.module
是父类)通过使用
super() 。代码>将与其父
__ INIT __
相同。例如,当您制作模型时:
model = Network()
通过调用此模型,实际上
nn.module
将处理此调用并跟踪更改。请访问 nn.module 源代码。
class Network(nn.Module)
means that you defined aNetwork
class that inherits all the methods and properties fromnn.Module
(Network
is child class andnn.Module
is parent class)By using
super().__init__()
, Network's__init__
will be same as its parent__init__
.For example when you make a model:
model = Network()
by calling this model, actually
nn.Module
will handle this call and track changes.visit this link if you want to see
nn.Module
source codes.