{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/calibrating-deep-neural-networks-using-focal","title":"Calibrating Deep Neural Networks using Focal Loss","arxiv_id":"2002.09437","date":"2020-02-21","proceeding":"NeurIPS 2020 12","authors":["Jishnu Mukhoti","Viveka Kulharia","Amartya Sanyal","Stuart Golodetz","Philip H. S. Torr","Puneet K. Dokania"],"abstract":"Miscalibration - a mismatch between a model's confidence and its correctness - of Deep Neural Networks (DNNs) makes their predictions hard to rely on. Ideally, we want networks to be accurate, calibrated and confident. We show that, as opposed to the standard cross-entropy loss, focal loss [Lin et. al., 2017] allows us to learn models that are already very well calibrated. When combined with temperature scaling, whilst preserving accuracy, it yields state-of-the-art calibrated models. We provide a thorough analysis of the factors causing miscalibration, and use the insights we glean from this to justify the empirically excellent performance of focal loss. To facilitate the use of focal loss in practice, we also provide a principled approach to automatically select the hyperparameter involved in the loss function. We perform extensive experiments on a variety of computer vision and NLP datasets, and with a wide variety of network architectures, and show that our approach achieves state-of-the-art calibration without compromising on accuracy in almost all cases. Code is available at https://github.com/torrvision/focal_calibration.","url_abs":"https://arxiv.org/abs/2002.09437v2","url_pdf":"https://arxiv.org/pdf/2002.09437v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"calibrating-deep-neural-networks-using-focal","repo_url":"https://github.com/torrvision/focal_calibration","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"calibrating-deep-neural-networks-using-focal","repo_url":"https://github.com/kclip/calibrating-bayesian-learning","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}},{"paper_slug":"calibrating-deep-neural-networks-using-focal","repo_url":"https://github.com/ondrejbohdal/meta-calibration","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[],"methods":[{"method_slug":"focal-loss","method_name":"Focal Loss"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2002.09437","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2002.09437"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ondrejbohdal/meta-calibration","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/torrvision/focal_calibration","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/kclip/calibrating-bayesian-learning","reach":{"status":"ok"}}],"summary":{"ran_draft_wrong":1,"ran_fixture":1,"unverified":12},"by_repo_kind":{"official":{"samples":13,"ran":1,"repositories":1},"listed":{"samples":1,"ran":1,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"6af95ebe99af2e36","entry":"conv3x3","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/wide_resnet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/wide_resnet.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6af95ebe99af2e36"}},{"code_sha256_prefix":"193b1a3f592079ed","entry":"get_logits_labels","repo":"ondrejbohdal/meta-calibration","repo_kind":"listed","path":"evaluate.py","file_url":"https://github.com/ondrejbohdal/meta-calibration/blob/HEAD/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"193b1a3f592079ed"}},{"code_sha256_prefix":"2ace1c98fa5f2cd5","entry":"conv3x3","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/resnet_tiny_imagenet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/resnet_tiny_imagenet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2ace1c98fa5f2cd5"}},{"code_sha256_prefix":"3f5c5480cc1592d7","entry":"cross_entropy","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Losses/loss.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Losses/loss.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3f5c5480cc1592d7"}},{"code_sha256_prefix":"a8ffeb2d34427847","entry":"densenet121","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/densenet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/densenet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a8ffeb2d34427847"}},{"code_sha256_prefix":"02ebf5964f8e25b5","entry":"densenet169","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/densenet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/densenet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"02ebf5964f8e25b5"}},{"code_sha256_prefix":"82dd30049f4202d8","entry":"densenet201","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/densenet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/densenet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"82dd30049f4202d8"}},{"code_sha256_prefix":"a60d17d88a279466","entry":"get_gamma","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Losses/focal_loss_adaptive_gamma.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Losses/focal_loss_adaptive_gamma.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a60d17d88a279466"}},{"code_sha256_prefix":"f3e49ddf8b75181f","entry":"resnet18","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/resnet_tiny_imagenet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/resnet_tiny_imagenet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f3e49ddf8b75181f"}},{"code_sha256_prefix":"98ed40c7f20ee013","entry":"resnet18","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/resnet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/resnet.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"98ed40c7f20ee013"}},{"code_sha256_prefix":"404c563a39af77bd","entry":"resnet34","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/resnet_tiny_imagenet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/resnet_tiny_imagenet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"404c563a39af77bd"}},{"code_sha256_prefix":"06b853e00fa53279","entry":"resnet34","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/resnet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/resnet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"06b853e00fa53279"}},{"code_sha256_prefix":"56b4d12881fdcf88","entry":"resnet50","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/resnet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/resnet.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"56b4d12881fdcf88"}},{"code_sha256_prefix":"a7629574fc5f15e3","entry":"wide_resnet_cifar","repo":"torrvision/focal_calibration","repo_kind":"official","path":"Net/wide_resnet.py","file_url":"https://github.com/torrvision/focal_calibration/blob/HEAD/Net/wide_resnet.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a7629574fc5f15e3"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}