Skip to content

Softmax関数を確率的解釈ができるようにキャリブレーションして、可視化するライブラリ

License

Notifications You must be signed in to change notification settings

Kageshimasu/temperature-scaling-optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temperature Scaling Optimizer

Temperature Scaling Optimizer is to calibrate your neural network and visualize how well-calibrated it in Pytorch.
This library is based on the below papers.

Table of Contents

  1. Features
  2. Installation
  3. Examples
  • Optimize for calibrating your neural network compatible with Cross Validation
  • Visualize how well-calibrated your neural network is
pip install -r requirements.txt

And you also install pytorch from here

To Optimize

import temp_opt as topt

model_dict = {
        model_1: DataLoader_1,
        model_2: DataLoader_2,
        model_3: DataLoader_3
        }
label_store = topt.label_stores.LogitsAndLabelsStore(topt.label_stores.PredictingTable(model_dict))
lbfgs_opt = topt.optimizers.LBFGSOptimizer(label_store, topt.trainers.TemperatureScaleTrainer())
lbfgs_opt.run()

To Predict with Temperature Scaling

import torch
import torchvision.models as models
import temp_opt as topt

model = models.resnet18(pretrained=True)
temperature = 5.32  # set an optimized temperature value 
predictor = topt.predictors.TemperatureScalePredictor(model, temperature)
inputs = torch.Tensor(34, 3, 32, 32)
print(predictor(inputs))

To Visualize

import matplotlib.pyplot as plt
import temp_opt as topt

model_dict = {
        model_1: DataLoader_1,
        model_2: DataLoader_2,
        model_3: DataLoader_3
        }
label_store = topt.label_stores.LogitsAndLabelsStore(topt.label_stores.PredictingTable(model_dict))
plotter = topt.visualizers.CalibationPlotter()
plotter.plot(label_store)
plt.show()

You can visualize your neural network as in the diagram below Visualize Sample

About

Softmax関数を確率的解釈ができるようにキャリブレーションして、可視化するライブラリ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages