z-hXu / ReCU

Pytorch implementation of our paper accepted by ICCV 2021 -- ReCU: Reviving the Dead Weights in Binary Neural Networks http://arxiv.org/abs/2103.12369
39 stars 8 forks source link

关于clamp #4

Closed WhereKey closed 3 years ago

WhereKey commented 3 years ago

你好,很感谢你出色的工作,让我打开了新的大门。但是我有一个疑问,经过clamp之后超过clamp范围的值的梯度都为0了,那这批权重直接无法更新,难道不是权重永远无法改变了。 class Clamp(Function):

@staticmethod
def forward(ctx, i, min_val, max_val):
    ctx._mask = (i.ge(min_val) * i.le(max_val))
    return i.clamp(min_val, max_val)

@staticmethod
def backward(ctx, grad_output):
    mask = Variable(ctx._mask.type_as(grad_output.data))
    return grad_output * mask, None, None
kriskrisliu commented 2 years ago

請問您對這個問題有答案了嗎?