[英]Piecewise Activation Function
我正在尝试编写分段激活 function,其 -6 和 0 之间的斜率为 0.1,其他地方为 1。 输入(X)大小为(B,C,H,W)。 所以我得出结论,最好的方法是简单的行代码:
x[-6<x and x<0] = x[-6<x and x<0] * 0.1
但我面临这个错误:
RuntimeError: bool value of Tensor with more than one value is ambiguous
有没有解决此错误的解决方案?
您需要的最简单版本是:
import torch
def custom_activ(input):
return torch.where((input>-6) & (input<0.) , 0.1*input, input)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.