函数“名称”未在类中定义错误,但已定义

时间:2021-07-18 08:50:01

标签: python class pytorch

我正在使用 Pytorch 定义神经网络,并且我正在使用类(我是业余爱好者)。 我的班级继承自 torch.nn.module, 在它的类的转发函数中,我使用了一个在转发函数之后定义的函数,但是当我运行代码时,出现以下错误。 “NameError:在定义中命名‘myspectral’” 结构如下图所示:

class shuffle(torch.nn.module):
        ..
        def forward(self, x):
            a = myspectral(x)
            ..
        def myspectral(self, x):
            ..

0 个答案:

没有答案
相关问题