我在写一个分段的活功能,其斜率之间的0-6和为0.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
是否有任何解决方案用于解决这个错误?
我在写一个分段的活功能,其斜率之间的0-6和为0.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)