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}$但这个似乎是错的。在
正确的答案是
相关问题 更多 >
编程相关推荐