fangwei123456 / Spike-Element-Wise-ResNet

Deep Residual Learning in Spiking Neural Networks
Mozilla Public License 2.0
140 stars 21 forks source link

还是导数计算,我又来啦 #3

Closed ghost closed 3 years ago

ghost commented 3 years ago

我写的钩子是下面这样的,不知道和您的是否一样?gradIn[0][1]应该是L对block输入的导数矩阵,然后计算二范数,最后除以了一个矩阵的大小。然后保存在grad中进行绘图。(.....表示缩进) def hook(module,gradIn,gradOut): .....shape=gradIn[0][1].shape .....num=shape[0]shape[1]shape[2]*shape[3] .....grad.append(np.linalg.norm(gradIn[0][1].detach().clone().cpu().double())/num)

fangwei123456 commented 3 years ago

我是直接保存 grad_input[0].norm().item()

ghost commented 3 years ago

好滴

ghost commented 3 years ago

最后绘图的结果,是不是需要除以num?gradIn就是上述代码中的那个形参 shape=gradIn[0].shape num=shape[0]shape[1]shape[2]shape[3]shape[4]

fangwei123456 commented 3 years ago

不需要除的,.norm()计算出的就是梯度矩阵的二范数,用二范数来表示“梯度的大小”

ghost commented 3 years ago

好滴