分段功能激活

0

的问题

我在写一个分段的活功能,其斜率之间的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

是否有任何解决方案用于解决这个错误?

1

最好的答案

1

最简单的版本为什么你需要的是:

import torch

def custom_activ(input):
    return torch.where((input>-6) & (input<0.) , 0.1*input, input)
2021-11-23 11:47:17

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................