BENN

October 7, 2019 ยท View on GitHub

Codes for Binary Ensemble Neural Network: More Bits per Network or More Networks per Bit?

CVPR 2019 Paper

:octocat: If using the code, please cite our paper: BibTex

If you have any question related to the codes or models, please open an issue. If you have general questions about principle of BENN or have any further idea of improving it, please contact us by email: shz338@eng.ucsd.edu, xindong@g.harvard.edu. Please, no commercial use before getting permission from authors.

Notice: As mentioned in the paper (Section 7) we are aware of the overfitting problem caused by the ensemble technique. If retraining the models, they should basically match the results shown in the paper as well as here, but could be either slightly higher or lower due to random initialization, epoch selection, overfitting, etc. If you have a good idea of how to resolve the overfitting issue of ensemble methods, please contact the authors and we can further improve BENN.

Train BENN on CIFAR-10 dataset

A customized Network-In-Network (NIN) model is used. Please see paper for architecture details.

EnsembleModelTrainLRBNN (start)BENN (end)Overfitting fromBest VotingModels DirectoryLogs
BaggingABSeq0.000167.3581.3220Soft Max VotemodelsL
BoostAABSeq0.0167.0881.9325Soft Max VotemodelsL
BoostAABIndp0.0170.5982.1220Soft Max VotemodelsL
BoostBABSeq0.0162.8782.5830Soft Max VotemodelsL
BoostBABIndp0.0169.6582.1321Soft Max VotemodelsL
BoostCABSeq0.000167.8879.4027Soft Max VotemodelsL
BoostDABIndp0.00168.7282.0422Soft Max VotemodelsL
BaggingSBSeq0.00177.8789.1225Soft Max VotemodelsL
BoostASBSeq0.0180.3388.1215Soft Max VotemodelsL
BoostBSBSeq0.00184.2387.931Soft Max VotemodelsL
BoostCSBSeq0.00183.6889.0025Soft Max VotemodelsL
BoostCSBIndp0.0180.3887.7223Soft Max VotemodelsL
BoostDSBSeq0.00184.588.8324Soft Max VotemodelsL

Hints

Generally, we have:

:house: 2 different models (you can specify with --arch allbinnet/nin), corresponding to AB and SB models in the paper

:hourglass_flowing_sand: 2 different training modes (independent training, and sequential training)

:gear: 5 different ensemble schemes (Bagging, Boost A, Boost B, Boost C, and Boost D)

:bar_chart: 2 voting strategies (hard majority vote, soft max vote)

Retrain models

For example:

$ python main_bagging_SB.py --epochs 0 --retrain_epochs 100 --root_dir PATH/TO/YOUR/models_bagging_SB/

Test pre-trained models

First download the models from the links above, then run the corresponding python script to test pre-trained models and you should get the exact same numbers comparing with our logs above. For example:

$ python main_bagging_SB.py --epochs 0 --retrain_epochs 0 --root_dir PATH/TO/YOUR/DOWNLOADED/models_bagging_SB/

Notice: For AB models, you should get around 79-82% accuracy for 32 ensembles. For SB models, you should get around 87-89% accuracy for 32 ensembles (usually 15-20 is a reasonable choice due to overfitting). The single BNN should have around 69-73% and 83-84% accuracy for AB and SB model respectively.

Train BENN on ImageNet dataset

Notice: Be sure to use SB model, and make sure each BNN is well converged before ensemble. Due to overfitting and optimization instability as observed in Section 6.2 from the paper, you may want to train BENN multiple times and pick the best combination. You may also explore model search on BENN.

ResNet-18 is presented here for best performance. We are currently testing the stability of gain of more ensembles up to 10 BNNs so please stay tuned. More uploaded models are coming soon (i.e., BENN-6 and BENN-10).

EnsembleModelTrainLRBNNBENN-3 EnsembleBest VotingModels DirectoryLogs
BaggingSBIndp0.00148.8754.34Soft Max Votemodelslogs
BoostSBIndp0.00148.8755.83Soft Max Votemodelslogs

Retrain models

For example:

$ python2 main_bagging_imagenet.py --epochs 0 --retrain_epochs 100 --root_dir PATH/TO/YOUR/models_bagging/

Test pre-trained models

For example:

$ python2 main_bagging_imagenet.py --epochs 0 --retrain_epochs 0 --root_dir PATH/TO/YOUR/DOWNLOADED/models_bagging/

As for other arguments, please refer to the head of the code for explanation. The retrained models will have different performance each time so feel free to play with multiple settings.

Train BENN on your own network architecture and dataset

To train BENN for your own application, you can directly reuse the BENN training part of this code. More details will be provided. If you successfully train BENN on some new applications with new architectures and achieve satisfying performance, please contact the authors and we will add a link here.

Acknowledgement

The single BNN training part of this code is mostly written by referencing XNOR-Net and Jiecao Yu's implementation. Please consider them as well if you use our code. Based on our testing, XNOR-Net is the most stable and reliable open source BNN training scheme with product-level codes.

Check list

  • Release CIFAR-10 Training Code
  • Release CIFAR-10 Pretrained Models
  • Release ImageNet Training Code
  • Release ImageNet Pretrained Models
  • Release Additional ImageNet Pretrained Models