簡體   English   中英

分段激活 Function

[英]Piecewise Activation Function

我正在嘗試編寫分段激活 function,其 -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

有沒有解決此錯誤的解決方案?

您需要的最簡單版本是:

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