本文重点
在神经网络搭建的时候,激活层是很重要的,本文讲解一下pytorch中已经封装好的激活函数,我们在使用的时候直接调用就可以了。
nn模块中部分激活函数的父类
class Threshold(Module):
__constants__ = ['threshold', 'value', 'inplace']
def __init__(self, threshold, value, inplace=False):
super(Threshold, self).__init__()
self.threshold = threshold
self.value = value
self.inplace = inplace
# TODO: check in THNN (if inplace == True, then assert value <= threshold)
@weak_script_method
def forward(self, input):
return F.threshold(input, self.threshold, self.value, self.inplace)
def extra_repr(self):
inplace_str = ', inplace' if self.inplace else ''
return 'threshold={}, value={}{}'.format(
self.thres