pytorch-book icon indicating copy to clipboard operation
pytorch-book copied to clipboard

第四章 多层感知机代码sigmoid

Open learnxy opened this issue 4 years ago • 1 comments

这一块代码不是应该先layer2后sigmoid然后结果作为返回,为什么是先sigmoid后layer2层是返回结果,是误写么?

learnxy avatar Jun 18 '20 06:06 learnxy

这一块代码不是应该先layer2后sigmoid然后结果作为返回,为什么是先sigmoid后layer2层是返回结果,是误写么?

确实写错了,可能作者笔误,问题不大,但是你的也不是正确的,正确写法是:

    def forward(self,x):
        x = self.layer1(x)
        x = t.sigmoid(x)
        x=self.layer2(x)
        return t.激活函数(x)

鉴于作者代码里out_features是1维,那激活函数就肯定不是softmax了,随便选个sigmoid relu...都随你

timmmGZ avatar Mar 02 '21 11:03 timmmGZ