小编Sus*_*usy的帖子

为什么不是 Pytorch 中的 super().__init__(Model,self)

对于 torch.nn.Module()

根据官方文档:所有神经网络模块的基类。你的模型也应该继承这个类。模块还可以包含其他模块,允许将它们嵌套在树结构中。您可以将子模块分配为常规属性。

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))
Run Code Online (Sandbox Code Playgroud)

它使用super(Model, self).__init__() 为什么不super().__init__(Model, self)

python oop inheritance class pytorch

2
推荐指数
1
解决办法
3370
查看次数

标签 统计

class ×1

inheritance ×1

oop ×1

python ×1

pytorch ×1