{"id":13738349,"url":"https://github.com/alvinwan/nbdt-pytorch-image-models","last_synced_at":"2025-07-26T03:04:44.270Z","repository":{"id":89467764,"uuid":"246800413","full_name":"alvinwan/nbdt-pytorch-image-models","owner":"alvinwan","description":"Neural-Backed Decision Tree sample integration with pytorch-image-models","archived":false,"fork":false,"pushed_at":"2020-09-18T23:02:04.000Z","size":14402,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T15:40:18.908Z","etag":null,"topics":["efficientnet","imagenet","neural-backed-decision-trees","pytorch"],"latest_commit_sha":null,"homepage":"http://nbdt.alvinwan.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alvinwan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-03-12T09:58:58.000Z","updated_at":"2024-06-25T02:08:30.000Z","dependencies_parsed_at":"2023-03-08T21:30:20.878Z","dependency_job_id":null,"html_url":"https://github.com/alvinwan/nbdt-pytorch-image-models","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alvinwan/nbdt-pytorch-image-models","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Fnbdt-pytorch-image-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Fnbdt-pytorch-image-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Fnbdt-pytorch-image-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Fnbdt-pytorch-image-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alvinwan","download_url":"https://codeload.github.com/alvinwan/nbdt-pytorch-image-models/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alvinwan%2Fnbdt-pytorch-image-models/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267109941,"owners_count":24037627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["efficientnet","imagenet","neural-backed-decision-trees","pytorch"],"created_at":"2024-08-03T03:02:19.599Z","updated_at":"2025-07-26T03:04:44.250Z","avatar_url":"https://github.com/alvinwan.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Sample [Neural-Backed Decision Trees](https://github.com/alvinwan/neural-backed-decision-trees) Integration with [pytorch-image-models](https://github.com/rwightman/pytorch-image-models)\n\n[Project Page](http://nbdt.alvinwan.com) \u0026nbsp;//\u0026nbsp; [Paper](http://nbdt.alvinwan.com/paper/) \u0026nbsp;//\u0026nbsp; [No-code Web Demo](http://nbdt.alvinwan.com/demo/) \u0026nbsp;//\u0026nbsp; [Colab Notebook](https://colab.research.google.com/github/alvinwan/neural-backed-decision-trees/blob/master/examples/load_pretrained_nbdts.ipynb)\n\nWondering what neural-backed decision trees are? See the [Neural-Backed Decision Trees](https://github.com/alvinwan/neural-backed-decision-trees) repository.\n\n**Table of Contents**\n\n- [Explanation](#explanation)\n- [Training and Evaluation](#training-and-evaluation)\n- [Results](#results)\n\n## Explanation\n\nThe full diff between the original repository `pytorch-image-models` and the integrated version is [here, using Github's compare view](https://github.com/alvinwan/nbdt-pytorch-image-models/compare/nbdt). There are a total of 9 lines added:\n\n1. Generate hierarchy (0 lines): Start by generating an induced hierarchy. We use a hierarchy induced from EfficientNet-B7.\n\n```bash\nnbdt-hierarchy --dataset=Imagenet1000 --arch=efficientnet_b7b\n```\n\n2. Wrap loss during training (3 lines): In `train.py`, we add the custom loss function. This is a wrapper around the existing loss functions.\n\n```python\nfrom nbdt.loss import SoftTreeSupLoss\ntrain_loss_fn = SoftTreeSupLoss(criterion=train_loss_fn, dataset='Imagenet1000', tree_supervision_weight=10, hierarchy='induced-efficientnet_b7b')\nvalidate_loss_fn = SoftTreeSupLoss(criterion=validate_loss_fn, dataset='Imagenet1000', tree_supervision_weight=10, hierarchy='induced-efficientnet_b7b')\n```\n\n3. Wrap model during inference (6 lines): In `validate.py`, we add NBDT inference. This is a wrapper around the existing model. We actually spend 4 lines adding and processing a custom `--nbdt` argument, so the actual logic for adding NBDT inference is only 2 lines.\n\n```python\nparser.add_argument('--nbdt', choices=('none', 'soft', 'hard'), default='none',\n                    help='Type of NBDT inference to run')\n...\nfrom nbdt.model import SoftNBDT, HardNBDT\nif args.nbdt != 'none':\n    cls = SoftNBDT if args.nbdt == 'soft' else HardNBDT\n    model = cls(model=model, dataset='Imagenet1000', hierarchy='induced-efficientnet_b7b')\n```\n\n## Training and Evaluation\n\nTo reproduce our results, **make sure to checkout the `nbdt` branch**.\n\n```bash\n# 1. git clone the repository\ngit clone git@github.com:alvinwan/nbdt-pytorch-image-models.git  # or http addr if you don't have private-public github key setup\ncd nbdt-pytorch-image-models\n\n# 2. install requirements\npip install -r requirements.txt\n\n# 3. checkout branch with nbdt integration\ngit checkout nbdt\n```\n\n**Training**: For our ImageNet results, we use the hyperparameter settings reported for ImageNet-EdgeTPU-Small found in the original README: [EfficientNet-ES (EdgeTPU-Small)](https://github.com/rwightman/pytorch-image-models#efficientnet-es-edgetpu-small-with-randaugment---78066-top-1-93926-top-5). Note the accuracy reported at this link is the average of 8 checkpoints. However, we use only 1 checkpoint, so we compare against the best single-checkpoint 77.23% result for EfficientNet-ES reported in the official [EfficientNet-EdgeTPU](https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet/edgetpu) repository. The hyperparameter settings reported in the first link are reproduced below:\n\n```bash\n./distributed_train.sh 8 /data/imagenetwhole/ilsvrc2012/ --model efficientnet_es -b 128 --sched step --epochs 450 --decay-epochs 2.4 --decay-rate .97 --opt rmsproptf --opt-eps .001 -j 8 --warmup-lr 1e-6 --weight-decay 1e-5 --drop 0.2 --drop-connect 0.2 --aa rand-m9-mstd0.5 --remode pixel --reprob 0.2 --amp --lr .064\n```\n\n**Validation**: To run inference, we use the following command. The majority of this command is typical for this repository. We simply add an extra `--nbdt` flag at the end for the type of NBDT we wish to run.\n\n```bash\npython validate.py /data/imagenetwhole/ilsvrc2012/val/ --model efficientnet_es --checkpoint=./output/train/20200319-185245-efficientnet_es-224/model_best.pth.tar --nbdt=soft\n```\n\n## Results\n\nNofE, shown below, was the strongest competing decision-tree-based method. Note that our NBDT-S outperforms NofE by ~14%. The acccuracy of the original neural network, EfficientNet-ES, is also shown. Our decision tree's accuracy is within 2% of the original neural network's accuracy.\n\n|                | NBDT-S (Ours) | NBDT-H (Ours) | NofE   | EfficientNet-ES |\n|----------------|---------------|---------------|--------|-----------------|\n| ImageNet Top-1 | 75.30%        | 74.79%        | 61.29% | 77.23%          |\n\nSee the original Neural-Backed Decision Trees [results](https://github.com/alvinwan/neural-backed-decision-trees#results) for a full list of all baselines. You can download our pretrained model and all associated logs at [v1.0](https://github.com/alvinwan/nbdt-pytorch-image-models/releases/tag/1.0).\n\n**For more information, return to the original [Neural-Backed Decision Trees](https://github.com/alvinwan/neural-backed-decision-trees) repository.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvinwan%2Fnbdt-pytorch-image-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falvinwan%2Fnbdt-pytorch-image-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falvinwan%2Fnbdt-pytorch-image-models/lists"}