Ultralytics YOLO27:
License YOLO
Back to Ultralytics Glossary

Temperature Scaling

Temperature scaling divides a model's logits by one fitted value before softmax so its confidence matches its accuracy, with predictions unchanged.

Temperature scaling is a post-hoc calibration method that divides a trained classifier's logits by a single positive number T before the softmax, with T chosen on held-out data so that the model's confidence matches how often it is actually right. A temperature above 1 softens overconfident probabilities, and a temperature below 1 sharpens underconfident ones. Dividing every logit by the same positive number keeps their order, so the predicted class never changes and accuracy stays exactly the same. In the study "On Calibration of Modern Neural Networks", Guo and colleagues found modern deep networks to be poorly calibrated and temperature scaling, a single-parameter variant of Platt scaling, to be surprisingly effective at calibrating them on most of the datasets they tested.

How Temperature Scaling Works#

The scaled softmax gives class i the probability exp(z_i / T) / Σ_j exp(z_j / T), where z are the logits. At T = 1 the model is unchanged, as T grows the probabilities approach a uniform distribution, and as T approaches 0 the top class's probability approaches 1. T is fitted after training by minimizing the negative log-likelihood (NLL), the same cross-entropy used as the training loss, on a held-out validation set with the network's weights frozen. With a single parameter, the fit takes seconds and leaves little room to overfit the validation set. The PyTorch script below fits T for a model whose logits are three times too large:

import torch
import torch.nn.functional as F

# Held-out logits for 5,000 images and 10 classes from an overconfident model:
# labels are drawn so that softmax(logits / 3) is perfectly calibrated
torch.manual_seed(0)
logits = 9 * torch.randn(5000, 10)
labels = torch.multinomial(F.softmax(logits / 3, dim=1), 1).squeeze(1)

# Fit the single temperature that minimizes negative log-likelihood (NLL) on the held-out set
temperatures = torch.linspace(0.5, 6.0, 551)
nll = torch.stack([F.cross_entropy(logits / t, labels) for t in temperatures])
T = temperatures[nll.argmin()]

# Accuracy depends only on the argmax, which dividing by T never changes
accuracy = (logits.argmax(1) == labels).float().mean()
before = F.softmax(logits, dim=1).max(1).values.mean()
after = F.softmax(logits / T, dim=1).max(1).values.mean()
print(f"T = {T:.2f}, accuracy {accuracy:.3f}")
print(f"Mean confidence: {before:.3f} before, {after:.3f} after")

The fit recovers T = 2.98, close to the true factor of 3. Accuracy stays at 0.663, while mean confidence falls from 0.880 to 0.664, so after scaling the model's average confidence matches its accuracy.

Why Networks Become Overconfident#

Cross-entropy training keeps rewarding larger logits on training examples the network already classifies correctly, so confidence keeps rising after accuracy on new data has leveled off. Guo and colleagues identified depth, width, weight decay, and batch normalization as important factors in miscalibration. Calibration is measured with reliability diagrams, which plot accuracy against confidence in bins, and with the expected calibration error (ECE), the average gap between confidence and accuracy across those bins, weighted by how many predictions fall in each. NLL and the Brier score also reward calibration. Calibration matters whenever a score is read as a probability, such as a medical triage rule that refers every case above 30% risk, a system that defers uncertain predictions to a person, or an active learning loop that picks the least confident images for labeling.

Temperature Scaling for Object Detectors#

Detectors usually score each class with an independent sigmoid instead of a softmax, and a temperature applies the same way, as sigmoid(z / T). With T above 1, scores move toward 0.5: high scores fall and low scores rise. In YOLO26, each box's confidence is the sigmoid of a class logit, compared against the conf threshold of 0.25 at prediction time, so a temperature fitted on held-out images changes which boxes clear that threshold while keeping the ranking of all boxes, which ranking metrics such as mean average precision (mAP) depend on.

Temperature in Other Settings#

  • Large language models (LLMs): Sampling temperature divides each next-token logit vector by T in the same way, and users set it by hand to trade diversity against determinism. As T approaches 0, sampling approaches greedy decoding, which always picks the most likely token.
  • Knowledge distillation: The distillation method of Hinton and colleagues raises the temperature of both teacher and student softmax outputs so the student learns the teacher's relative probabilities for the wrong classes.
  • Contrastive learning: Models such as CLIP divide image-text similarity scores by a learned temperature before the softmax, which controls how sharply the loss separates matching pairs from the rest.
  • Platt scaling: Fits a slope and an intercept to a binary classifier's score before a sigmoid. Temperature scaling extends it to many classes with one shared slope, 1 / T, and no intercept.
  • Vector and matrix scaling: Learn a separate weight and bias for each class, or a full matrix over the logits. They are more flexible, overfit more easily, and can change the predicted class.
  • Isotonic regression: A non-parametric, monotonic mapping from score to probability, available with Platt scaling in scikit-learn's calibration tools.
  • Label smoothing: Softens the training targets, such as 0.9 instead of 1.0 for the true class, to reduce overconfidence during training. Temperature scaling changes only the outputs of a finished model.
  • Conformal prediction: Turns scores into prediction sets that contain the true label at a guaranteed rate, such as 90% of the time, on exchangeable data.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning