深度学习与PyTorch入门实战 - 18.1 激活函数梯度a=torch.linspace(-1,1,10) In [13]: torch.relu(a) Out[13]: tensor([0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.1111, 0.3333, 0.5556, 0.7778, 1.0000]) In [14]: F.relu(a) Out[14]: tensor([0.0000, 0.0000,0 码力 | 14 页 | 724.00 KB | 2 年前3
深度学习与PyTorch入门实战 - 27. MLP网络层torch.Size([1, 10]) ## relu? ## ☐ ☐ ☐ In [49]: x=layer1(x) In [56]: x=F.relu(x, inplace=True) In [50]: x.shape Out[50]: torch.Size([1, 200]) In [52]: x=layer2(x) In [56]: x=F.relu(x, inplace=True) In In [53]: x.shape Out[53]: torch.Size([1, 200]) In [54]: x=layer3(x) In [56]: x=F.relu(x, inplace=True) In [55]: x.shape Out[55]: torch.Size([1, 10]) ## concisely ☑ inherit from nn.Module - init Sequential( nn.Linear(784, 200), nn.ReLU(inplace=True), nn.Linear(200, 200), nn.ReLU(inplace=True), nn.Linear(200, 10), nn.ReLU(inplace=True), Step3. ☐ ☐ ☐ class MLP(nn.Module):0 码力 | 13 页 | 992.88 KB | 2 年前3
深度学习与PyTorch入门实战 - 39. Pooling Sampling## PyTorch ## Down/up sample 主讲人:龙良曲 ## Outline - Pooling - upsample ReLU ## Downsample |A|B| |---|---| |C|D| Scaling factor : 2 |A|A|B|B| |---|---|---|---| |A|A|B|B| |C|C|D|D| |C|C|D|D| ## Max torch.Size([1, 16, 7, 7]) In [44]: layer=nn.ReLU(inplace=True) In [45]: out=layer(x) In [46]: out.shape Out[46]: torch.Size([1, 16, 7, 7]) In [47]: out=F.relu(x) In [48]: out.shape Out[48]: torch.Size([10 码力 | 13 页 | 749.97 KB | 2 年前3
keras tutorialfrom keras.layers import Dense, Activation model = Sequential() model.add(Dense(512, activation='relu', input_shape=(784,))) Where. • Line 1 imports Sequential model from Keras models • Line 2 4 create a new sequential model using Sequential API - Line 5 adds a dense layer (Dense API) with relu activation (using Activation module) function. Sequential model exposes Model class to create customized = Sequential() model.add(Dense(512, activation='relu', input_shape=(784,))) model.add(Dropout(0.2)) model.add(Dense(512, activation='relu')) model.add(Dropout(0.2)) model.add(Dense(num_classes0 码力 | 98 页 | 1.57 MB | 2 年前3
【PyTorch深度学习-龙龙老师】-测试版202112来。2011 年,Xavier Glorot 提出了线性整流单元(Rectified Linear Unit,简称 ReLU)激活函数,这是现在使用最为广泛的激活函数之一。2012 年,Alex Krizhevsky 提出了 8 层的深层神经网络 AlexNet,它采用了 ReLU 激活函数,并使用 Dropout 技术来防止过拟合,同时抛弃了逐层预训练的方式,直接在两块 NVIDIA GTX580 ymbol{W}\boldsymbol{x}+\boldsymbol{b}) $$ 这里的 $ \sigma $ 代表了某个具体的非线性激活函数,如 Sigmoid 函数(图 3.9(a))、ReLU 函数(图 3.9(b))。  (a) jpg) (b) ReLU 函数 图 3.9 常见激活函数 ReLU 函数非常简单,它在 y = x 的基础上面截去了 x < 0 的部分,可以直观地理解为 ReLU 函数仅保留正的输入部分,清零负的输入,具有单边抑制特性。虽然简单,ReLU 函数却有优良的非线性特性,而且梯度计算非常简单,训练稳定,是深度学习中使用最广泛的激活函数。因此,这里通过嵌套 ReLU 函数将模型转换为非线性模型:0 码力 | 439 页 | 29.91 MB | 2 年前3
机器学习课程-温州大学-04深度学习-深层神经网络tanh函数是sigmoid的向下平移和伸缩后的结果。对它进行了变形后,穿过了 $ (0,0) $ 点,并且值域介于+1和-1之间。 tanh函数是总体上都优于sigmoid函数的激活函数。 ### 3. 激活函数 ## ReLu函数 $$ a=max(0,z) $$ 在输入是负值的情况下,它会输出0,那么神经元就不会被激活。这意味着同一时间只有部分神经元会被激活,从而使得网络很稀疏,进而对计算来说是非常有效率的。 jpg) ### 3. 激活函数 Leaky ReLU 函数 $$ a=max(0.01z,z) $$  Leaky ReLu通常比Relu激活函数效果要好,尽管在实际中Leaky ReLu使用的并不多。 ### 3. 激活函数的使用场景 激活函数的使用场景 Sigmoid激活函数:除了输出层是一个二分类问题基本不会用它。 Tanh激活函数:tanh是非常优秀的,几乎适合所有场合。 ReLu激活函数:最常用的默认函数,,如果不确定用哪个激活函数,就使用ReLu或者Leaky ReLu。 ### 4. 反向传播算法 $$ \begin{aligned}\left.\begin{array}{l}x\\w\\b\end{array}\right\}\Longrightarrow0 码力 | 28 页 | 1.57 MB | 2 年前3
Keras: 基于 Python 的深度学习库[source] ..... 110 5.9.4 ThresholdedReLU [source] ..... 110 5.9.5 Softmax [source] ..... 110 5.9.6 ReLU [source] ..... 111 5.10 标准化层 Normalization ..... 112 5.10.1 BatchNormalization [source] ..... .... 143 10.2.3 selu ..... 144 10.2.4 softplus ..... 144 10.2.5 softsign ..... 144 10.2.6 relu ..... 144 10.2.7 tanh ..... 144 10.2.8 sigmoid ..... 144 10.2.9 hard_sigmoid ..... 144 10 Sequential() 可以简单地使用 .add() 来堆叠模型: from keras.layers import Dense model.add(Dense(units=64, activation='relu', input_dim=100)) model.add(Dense(units=10, activation='softmax')) 在完成了模型的构建后, 可以使用0 码力 | 257 页 | 1.19 MB | 2 年前3
全连接神经网络实战. pytorch 版定义网络的计算顺序 self.linear_relu_stack = nn.Sequential( nn.Linear(28*28, 512), nn.ReLU(), # 使用ReLU做激活函数 nn.Linear(512, 512), nn.ReLU(), nn.Linear(512 logits = self.linear_relu_stack(x) return logits model = NeuralNetwork() print(model) 这里使用 Relu 做激活函数,本想用最基本的 Sigmoid 函数,但 Sigmoid 函数训练效果实在是太差,因此还是换成 ReLU 吧。有的人可能会疑惑输出为什么不用在 forward 里面定义 01) 注意,我们把 key 打印出来以后得到: linear_relu_stack.0.weight linear_relu_stack.0.bias linear_relu_stack.2.weight linear_relu_stack.2.bias linear_relu_stack.4.weight linear_relu_stack.4.bias 也就是说 weight 和 bias0 码力 | 29 页 | 1.40 MB | 2 年前3
动手学深度学习 v2.0torch as d2l ## ReLU函数 最受欢迎的激活函数是修正线性单元(Rectified linear unit, ReLU),因为它实现简单,同时在各种预测任务中表现良好。ReLU提供了一种非常简单的非线性变换。给定元素x,ReLU函数被定义为该元素与0的最大值: $$ \mathbf{ReLU}(x)=\max(x,0). $$ 通俗地说,ReLU函数通过将相应的活性值设为0, requires_grad=True) y = torch.relu(x) d2l.plot(x.detach(), y.detach(), 'x', 'relu(x)', figsize=(5, 2.5)) 当输入为负时,ReLU函数的导数为0,而当输入为正时,ReLU函数的导数为1。注意,当输入值精确等于0时,ReLU函数不可导。在此时,我们默认使用左侧的导数,即当输入 非工程”,这个观点正好适用于这里。下面我们绘制ReLU函数的导数。 y.backward(torch.ones_like(x), retain_graph=True) d2l.plot(x.detach(), x.grad, 'x', 'grad of relu', figsize=(5, 2.5)) 使用ReLU的原因是,它求导表现得特别好:要么让参数消失,要0 码力 | 797 页 | 29.45 MB | 2 年前3
机器学习课程-温州大学-08深度学习-深度卷积神经网络x): x = F.relu(self.conv1(x)) x = F.avg_pool2d(x, 2) x = F.relu(self.conv2(x)) x = F.avg_pool2d(x, 2) x = x.view(-1, 16 * 5 * 5) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) s/7/6/0/7/7607a8e8efef5c4a56eb4c0c25195190/p7_1.jpg) ## AlexNet ## AlexNet 将 sigmoid 激活函数改为更简单的 ReLU 激活函数。 class AlexNet(nn.Module): def __init__(self): super(AlexNet, self).__init__() forward(self, x): x = F.relu(self.conv1(x)) x = self.pool1(x) x = F.relu(self.conv2(x)) x = self.pool2(x) x = F.relu(self.conv3(x)) x = F.relu(self.conv4(x)) x = F.relu(self.conv5(x))0 码力 | 32 页 | 2.42 MB | 2 年前3
共 54 条
- 1
- 2
- 3
- 4
- 5
- 6













