torchcal

post-hoc calibration on GPU

https://github.com/rishabh-ranjan/torchcal

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (8.3%) to scientific vocabulary

Keywords

calibration pytorch temperature-scaling
Last synced: 10 months ago · JSON representation ·

Repository

post-hoc calibration on GPU

Basic Info
  • Host: GitHub
  • Owner: rishabh-ranjan
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 17.6 KB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Topics
calibration pytorch temperature-scaling
Created about 3 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

torchcal: post-hoc calibration on GPU

This package provides PyTorch implementations (including GPU support) of post-hoc calibration techniques commonly employed for deep neural networks.

Methods include Temperature, Vector and Matrix Scaling from the paper "On calibration of modern neural networks", and BCTS and NBVS from "Maximum likelihood with bias-corrected calibration is hard-to-beat at label shift adaptation".

install

bash pip install git+https://github.com/rishabh-ranjan/torchcal

use

```python cal = torchcal.calibrator("temp_scaler", device=device)

yhat = predicted logits, y = true class labels

cal.fit(yhatval, yval) print("fitted temperature = ", cal.temp.item())

yhattest = cal(yhattest) ```

```python cal = torchcal.calibrator("vectorscaler", numclasses, device=device)

yhat = predicted logits, y = true class labels

cal.fit(yhatval, yval)

yhattest = cal(yhattest) ```

Supported calibrators (and number of calibration parameters) are: python [ "temp_scaler", # 1 "no_bias_vector_scaler", # num_classes "bias_corrected_temp_scaler", # num_classes + 1 "vector_scaler", # num_classes * 2 "no_bias_matrix_scaler", # num_classes ** 2 "matrix_scaler", # num_classes ** 2 + num_classes ]

cite

If you use this package, please consider citing us and the pytorch-minimize library:

bibtex @misc{ranjan2023torchcal, author = {Ranjan, Rishabh}, title = {{torchcal}: post-hoc calibration on {GPU}}, publisher = {GitHub}, year = {2023}, url = {https://github.com/rishabh-ranjan/torchcal}, version = {1.0.0}, }

bibtex @misc{feinman2021pytorch, author = {Feinman, Reuben}, title = {Pytorch-minimize: a library for numerical optimization with autograd}, publisher = {GitHub}, year = {2021}, url = {https://github.com/rfeinman/pytorch-minimize}, }

and the original papers:

bibtex @inproceedings{guo2017calibration, title={On calibration of modern neural networks}, author={Guo, Chuan and Pleiss, Geoff and Sun, Yu and Weinberger, Kilian Q}, booktitle={International conference on machine learning}, pages={1321--1330}, year={2017}, organization={PMLR} }

bibtex @inproceedings{alexandari2020maximum, title={Maximum likelihood with bias-corrected calibration is hard-to-beat at label shift adaptation}, author={Alexandari, Amr and Kundaje, Anshul and Shrikumar, Avanti}, booktitle={International Conference on Machine Learning}, pages={222--232}, year={2020}, organization={PMLR} }

Owner

  • Name: Rishabh Ranjan
  • Login: rishabh-ranjan
  • Kind: user
  • Location: Pittsburgh, Pennsylvania
  • Company: CMU

visiting researcher at CMU (@acmi-lab). '22 CS graduate from IIT Delhi (@dair-iitd, @idea-iitd)

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this package, please cite it as below."
authors:
- family-names: "Ranjan"
  given-names: "Rishabh"
title: "torchcal: post-hoc calibration on GPU"
version: 1.0.0
url: "https://github.com/rishabh-ranjan/torchcal"

GitHub Events

Total
Last Year

Dependencies

pyproject.toml pypi
  • pytorch-minimize *
  • torch *
setup.py pypi