我想用pytorch写一些简单的神经网络。我是新来这个图书馆的。我面临着两种实现相同想法的方法:一种具有固定激活功能的层(例如tanh)。你知道吗
第一种实现方法:
l1 = nn.Tanh(n_in, n_out)
第二种方式:
l2 = nn.Linear(n_in, n_out) # linear layer, that do nothing with its input except summation
但在前向传播中:
import torch.nn.functional as F
x = F.tanh(l2(x)) # x - value that propagates from layer to layer
这些机制之间有什么区别?哪一个更适合哪一个目的?你知道吗
激活函数只是一个非线性函数,它没有任何参数。所以,你的第一个方法没有任何意义!你知道吗
但是,可以使用sequential包装器将线性层与
tanh
激活结合起来。你知道吗相关问题 更多 >
编程相关推荐