pytorch激活函数--LeakyReLU()

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a19990412/article/details/83930455

简述

以前都是用ReLU(),第一见到LeakyReLU(),就研究了下源码中的注释。

函数图像

LeakyReLU()是有一个参数的。
其实不难猜到,这个参数就是在小于0的部分的曲线的斜率。

在这里插入图片描述

代码

import torch
import torch.nn as nn
from torch.autograd import Variable
import matplotlib.pyplot as plt
import numpy as np
x = Variable(torch.linspace(-10, 10, 101))
varis = np.linspace(0.01, 1, 10)
for v in varis:
    y = nn.LeakyReLU(v)(x)
    plt.plot(x.data.numpy(), y.data.numpy(), label='v=%.3f' % v)
plt.legend()
plt.show()

猜你喜欢

转载自blog.csdn.net/a19990412/article/details/83930455