简体   繁体   English

分段激活 Function

[英]Piecewise Activation Function

I'm trying to write a piecewise activation function whose slope between -6 and 0 is 0.1 and the other places are one.我正在尝试编写分段激活 function,其 -6 和 0 之间的斜率为 0.1,其他地方为 1。 And the input(X) size is (B, C, H, W).输入(X)大小为(B,C,H,W)。 So I concluded that the best way is the simple line code:所以我得出结论,最好的方法是简单的行代码:

 x[-6<x and x<0] = x[-6<x and x<0] * 0.1

But I face this error:但我面临这个错误:

RuntimeError: bool value of Tensor with more than one value is ambiguous

Is there any solution for solving this error?有没有解决此错误的解决方案?

The most simple version of what you need is:您需要的最简单版本是:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM