我试着写一个分段激活函数,它的斜率在-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有没有解决这个错误的方法?
发布于 2021-11-23 11:47:17
你需要的最简单的版本是:
import torch
def custom_activ(input):
return torch.where((input>-6) & (input<0.) , 0.1*input, input)https://stackoverflow.com/questions/70079367
复制相似问题