1 Star 0 Fork 0

蛋蛋编程 / Swish激活函数

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Swish.py 994 Bytes
一键复制 编辑 原始数据 按行查看 历史
蛋蛋编程 提交于 2021-11-20 13:52 . Swish激活函数
# -*- coding: UTF-8 -*-
import torch
import matplotlib.pyplot as plt
import torch.nn as nn
class Swish(nn.Module):
def __init__(self, beta):
super(Swish, self).__init__()
self.beta = beta
def forward(self, x):
x = x * torch.sigmoid(self.beta*x)
return x
def Curve01(x, beta:list):
swish0 = Swish(beta[0])
y0 = swish0(x)
swish1 = Swish(beta[1])
y1 = swish1(x)
swish2 = Swish(beta[2])
y2 = swish2(x)
swish3 = Swish(beta[3])
y3 = swish3(x)
plt.title('Swish')
plt.plot(x, y0, color='green', label='SMU,β=0.1')
plt.plot(x, y1, color='blue', label='SMU,β=1')
plt.plot(x, y2, color='red', label='SMU,β=5')
plt.plot(x, y3, '--', color='skyblue', label='SMU,β=10')
plt.legend()
plt.grid(True, linestyle='--', alpha=0.8)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
if __name__ == '__main__':
x = torch.linspace(-3, 3, 10000)
beta = [0.1, 1, 5, 10]
Curve01(x, beta=beta)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/luokai-dandan/swish-activation-function.git
git@gitee.com:luokai-dandan/swish-activation-function.git
luokai-dandan
swish-activation-function
Swish激活函数
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891