BinaryNet.pytorch icon indicating copy to clipboard operation
BinaryNet.pytorch copied to clipboard

Activation for BinaryNet

Open ruizhoud opened this issue 7 years ago • 1 comments

Hello,

I noticed that torch.nn.Hardtanh is used for activation functions in BinaryNet. This is meant to make the model trainable, as introduced in the BNN paper. However, in the inference phase (the validate() function in main_binary.py), shoudn't the activation function be changed to sign function so that the intermediate results are binary?

Thanks!

ruizhoud avatar Feb 02 '18 03:02 ruizhoud

Check out binarized_modules: https://github.com/itayhubara/BinaryNet.pytorch/blob/master/models/binarized_modules.py#L76 and https://github.com/itayhubara/BinaryNet.pytorch/blob/master/models/binarized_modules.py#L95

You will see that the input to each layer is Binarized anyway so as long as you use BinarizeConv2d or BinarizeLinear you are good.

roeemz avatar Mar 19 '18 14:03 roeemz