东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 4372|回复: 0
打印 上一主题 下一主题

[课堂笔记] mish激活函数的pytorch和numpy实现

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14435
QQ
跳转到指定楼层
楼主
发表于 2020-11-16 11:27:20 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式


# mish激活函数的pytorch和numpy实现
import torch


import numpy as np
import math
import matplotlib.pyplot as plt




# class Mish(torch.nn.Module):
#     def __init__(self):
#         super().__init__()
#
#     def forward(self, x):
#         x = x * (torch.tanh(torch.nn.functional.softplus(x)))
#         return x


e = math.e




def tanh(x):
    # 双曲正切
    return (e ** x - e ** (-x)) / (e ** x + e ** (-x))




def softplus(x):
    # softplus可以看作是ReLu的平滑。根据神经科学家的相关研究,
    # softplus和ReLu与脑神经元激活频率函数有神似的地方
    return math.log(1 + pow(e, x))




def mish(x):
    return x * tanh(softplus(x))




x = np.linspace(-5, 5, 1000)
y = np.linspace(-5, 5, 1000)
for i in range(1000):
    y = mish(x)
plt.plot(x, y, color='orange', linewidth=2, label='Mish')
plt.legend()
plt.savefig('mish.jpg')
plt.show()


mish.jpg (21.88 KB, 下载次数: 117)

mish.jpg
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-4-26 16:59 , Processed in 0.188431 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表