🔁 sigmoid vs softmax
特性 | sigmoid | softmax |
---|---|---|
📌 定义 | σ(x)=11+e−x\sigma(x) = \frac{1}{1 + e^{-x}}σ(x)=1+e−x1 | softmax(xi)=exi∑jexj\text{softmax}(x_i) = \frac{e^{x_i}}{\sum_j e^{x_j}}softmax(xi)=∑jexjexi |
📊 输出范围 | 每个值在 [0,1][0, 1][0,1],互相 独立 | 所有输出加起来为 1(形成 概率分布) |
🔢 输出总和 | 不固定 | 恒为 1 |
✅ 用在哪 | 二分类或多标签(二分类) | 多分类(互斥) |
🧠 用的损失函数 | BCEWithLogitsLoss (或 BCELoss + sigmoid) | CrossEntropyLoss (自动带 softmax) |
⚠️ 类别之间的关系 | 无竞争,非互斥标签 | 有竞争,互斥类别 |
📦 PyTorch 中是否需要显式调用? | 是的(除非用了 BCEWithLogitsLoss ) | 否,CrossEntropyLoss 自带 softmax |