簡體   English   中英

L2矩陣逐行歸一化梯度

[英]L2 matrix rowwise normalization gradient

我試圖為卷積神經網絡實現L2范數層,並且陷入了向后的障礙:

def forward(self, inputs):
    x, = inputs
    self._norm = np.expand_dims(np.linalg.norm(x, ord=2, axis=1), axis=1)
    z = np.divide(x, self._norm)
    return z,

def backward(self, inputs, grad_outputs):
    x, = inputs
    gz, = grad_outputs
    gx = None # how to compute gradient here?
    return gx,

如何計算gx? 我的第一個猜測是

gx = - gz * x / self._norm**2

但這似乎是錯誤的。

正確的答案是

gx = np.divide(gz, self._norm)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM