激活函数曲线图

SiLUHardswishMish

import numpy as np
import torch
import torch.nn.functional as F

from matplotlib import pyplot as plt

def SiLu(x):
    return x * torch.sigmoid(x)

def Hardswish(x):
    return x * F.hardtanh(x + 3, 0.0, 6.0) / 6.0

def Mish(x):
    return x * F.softplus(x).tanh()

if __name__ == "__main__":
    x = torch.tensor(np.linspace(-6, 6, 1000))

    silu = []
    hswish = []
    mish = []

    for i in x:
        silu.append(SiLu(i))
        hswish.append(Hardswish(i))
        mish.append(Mish(i))

    plt.plot(x, silu)
    # plt.plot(x, hswish)
    plt.plot(x, mish)
    plt.ylim((-7, 7))
    plt.grid()
    plt.show()

你可能感兴趣的:(绘图,python,深度学习,激活函数)