Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Model Weights

Model weights are the learned numbers that turn a network's inputs into predictions. Covers how training sets them, weight files, and compression.

Model weights are the learnable numbers inside a neural network that transform its inputs into predictions. Each weight scales the signal passing between two units, or forms one value of a convolution filter, and together the weights encode everything the model has learned from its training data. The term is often used loosely for all of a model's learned parameters, including biases and normalization values, as in "pretrained weights" or "open-weight models". Weight counts span orders of magnitude: ResNet-50 has about 25.6 million parameters, while large language models have billions.

How Training Sets the Weights#

A new network starts with small random weights drawn from schemes such as He initialization, which scale the random values to each layer's size so signals neither vanish nor explode as they pass through many layers. At this point the model's predictions are noise. Training then repeats a cycle for each batch of data: a forward pass produces predictions, a loss function scores their error, backpropagation computes how much each weight contributed to that error, and an optimizer such as stochastic gradient descent (SGD) or the Adam optimizer nudges every weight to reduce it. After millions of these small updates, the weights settle into values that produce accurate predictions, and they stay fixed during inference.

  • Biases: In a layer that computes y = Wx + b, the weights W multiply the inputs and the bias b adds an offset, which lets a unit's activation function shift its threshold and produce a nonzero output when every input is zero. Both are learned during training.
  • Hyperparameters: Settings such as the learning rate and batch size that are chosen before training and control how the weights are learned. Gradient descent does not update them.
  • Activations: The intermediate outputs a network computes for a particular input. Weights stay the same for every input, while activations are recomputed for each one.
  • Weights & Biases: An experiment-tracking platform whose name borrows the two parameter types.

Saving and Loading Weights#

Trained weights are saved to files so they can be reloaded for inference, shared, or used as the starting point for transfer learning. In PyTorch, a model's weights live in its state_dict and are usually saved to .pt files. These files use Python's pickle format, which can execute code when loaded, so since PyTorch 2.6 torch.load defaults to weights_only=True. The safetensors format stores raw tensors only, which rules out code execution and allows fast memory-mapped loading, and it is the standard format on Hugging Face. ONNX files package the weights together with the computation graph so other runtimes can execute the model.

Ultralytics YOLO26 .pt checkpoints store an exponential moving average (EMA) of the weights, which smooths out step-to-step noise, together with the training arguments and per-epoch results, and every training run writes best.pt and last.pt to its weights folder. Loading the same architecture with and without trained weights shows where the model's knowledge lives:

from ultralytics import YOLO

# Same YOLO26n architecture with two different sets of weights
trained = YOLO("yolo26n.pt")  # weights learned on COCO
untrained = YOLO("yolo26n.yaml")  # randomly initialized weights

for name, model in [("trained", trained), ("untrained", untrained)]:
    results = model("https://ultralytics.com/images/bus.jpg")
    print(f"{name}: {len(results[0].boxes)} objects detected")

The trained weights find the bus and the people in the image, while the randomly initialized copy of the identical network detects nothing.

Compressing Weights for Deployment#

Weight precision sets a model's file size and memory footprint, which matters most for edge AI devices. Model quantization stores weights at lower precision, and moving from 32-bit floating point to 8-bit integers makes them four times smaller and speeds up inference on hardware with integer support. Pruning removes weights that contribute little to the output, and knowledge distillation trains a smaller model to mimic a larger one. For scale, a 7-billion-parameter language model needs about 28 GB for its weights at 32 bits, 14 GB at 16 bits, and 3.5 GB at 4 bits.

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

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

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
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