Python 3.9/Pytorch:如何制作具有多个 softmax 输出的神经网络?

问题描述 投票:0回答:1

我正在制作一个神经网络,它接受 10 个输入并输出 5 个 0 到 1 的值。它不是一个分类器,它更像是一个方框勾选问题,所以通常它有多个输出节点为 1。

我不确定如何在 pytorch 中表示这一点,因为 nn.softmax() 函数不像 nn.Linear 那样将输入输出的数量作为参数。

class NeuralNet(nn.Module):
    def __init__(self, input_size, hidden_size, num_classes):
        super(NeuralNet, self).__init__()
        self.fc1 = nn.Linear(input_size, hidden_size) 
        self.relu = nn.ReLU()
        self.fc2 = nn.Linear(hidden_size, num_classes)  
    
    def forward(self, x):
        out = self.fc1(x)
        out = self.relu(out)
        out = self.fc2(out)
        return out

还有哪些标准/优化器支持多目标输出?因为 CrossEntropyLoss、SGD 和 Adam 没有

python pytorch neural-network
1个回答
0
投票

您所描述的是二元分类输出。您应该使用

BCEWithLogitsLoss

© www.soinside.com 2019 - 2024. All rights reserved.