L2矩阵行归一化梯度

2024-06-26 14:50:06 发布

您现在位置:Python中文网/ 问答频道 /正文

Im尝试为卷积神经网络实现L2范数层,而Im卡在反向传递上:

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? 我的第一个猜测是

^{pr2}$

但这个似乎是错的。在


Tags: selfnormreturndefnp神经网络outputs卷积