【问题标题】:Piecewise Activation Function分段激活函数
【发布时间】:2022-01-01 20:33:00
【问题描述】:

我正在尝试编写一个分段激活函数,其 -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

有解决这个错误的办法吗?

【问题讨论】:

    标签: python deep-learning pytorch boolean activation-function


    【解决方案1】:

    你需要的最简单的版本是:

    import torch
    
    def custom_activ(input):
        return torch.where((input>-6) & (input<0.) , 0.1*input, input)
    

    【讨论】:

      猜你喜欢
      • 2018-02-05
      • 2018-08-14
      • 2021-05-19
      • 2018-01-27
      • 1970-01-01
      • 2014-12-17
      • 1970-01-01
      • 2020-12-24
      • 2023-03-12
      相关资源
      最近更新 更多