Skip to content

Source Code for ICML 2019 Paper "Shallow-Deep Networks: Understanding and Mitigating Network Overthinking"


Notifications You must be signed in to change notification settings


Repository files navigation

[ICML 2019] Shallow-Deep Networks (Website:

This repository contains the code for reproducing the results in our paper:


We characterize a prevalent weakness of deep neural networks (DNNs)-overthinking-which occurs when a DNN can reach correct predictions before its final layer. Overthinking is computationally wasteful, and it can also be destructive when, by the final layer, a correct prediction changes into a misclassification. Understanding overthinking requires studying how each prediction evolves during a DNN's forward pass, which conventionally is opaque. For prediction transparency, we propose the Shallow-Deep Network (SDN), a generic modification to off-the-shelf DNNs that introduces internal classifiers. We apply SDN to four modern architectures, trained on three image classification tasks, to characterize the overthinking problem. We show that SDNs can mitigate the wasteful effect of overthinking with confidence-based early exits, which reduce the average inference cost by more than 50% and preserve the accuracy. We also find that the destructive effect occurs for 50% of misclassifications on natural inputs and that it can be induced, adversarially, with a recent backdooring attack. To mitigate this effect, we propose a new confusion metric to quantify the internal disagreements that will likely lead to misclassifications.



  • Python 3.7
  • PyTorch 1.0
  • CUDA 8.0
  • CUDNN 7.5
  • Matplotlib Pyplot

Required data sets:

  • CIFAR-10/100 (downloaded automatically)
  • Tiny ImageNet
  • Download and place it under data/ and use - create_val_folder() to generate proper directory structure

Reproducing the results

Source code files and corresponding sections in the paper:

  • Section 3.0: The Shallow-Deep Network --- SDNs/, SDNs/, SDNs/ and SDNs/ implements the SDNs, trains CNNs and SDNs

  • Section 4.0: Understanding the Overthinking Problem --- quantifies the wasteful and destructive effects and generates the explanatory images

  • Section 5.1: Confidence-based Early Exits --- searches for the early-exit threshold and returns the average inference cost for early exits

  • Section 5.2: Network Confusion Analysis/Confusion Metric is an Error Indicator --- computes the normalized confusion scores and generates the confusion histogram of the SDN on correct and wrong classifications.

  • Section 5.2: Network Confusion Analysis/Visualizing Confusion Helps with Error Diagnosis --- finds the test samples that are classified correctly by the first internal classifier and wrongly by the final classifier and uses GradCam to visualize the prominent features that lead to this disagreement

Cite Our Work

Please cite our work if you find our work is helpful.

  title={Shallow-Deep Networks: Understanding and Mitigating Network Overthinking},
  author={Kaya, Yigitcan and Hong, Sanghyun and Dumitras, Tudor},
  booktitle={Proceedings of the 36th International Conference on Machine Learning},
  editor={Chaudhuri, Kamalika and Salakhutdinov, Ruslan},
  series={Proceedings of Machine Learning Research},
  month={09--15 Jun},


Please contact Yigitcan Kaya for any questions and recommendations.


Source Code for ICML 2019 Paper "Shallow-Deep Networks: Understanding and Mitigating Network Overthinking"







No releases published