Yolo Tầm nhìn Thâm Quyến
Thâm Quyến
Tham gia ngay
Bảng chú giải thuật ngữ

Trọng số Mô hình

Khám phá tầm quan trọng của trọng số mô hình trong học máy, vai trò của chúng trong dự đoán và cách Ultralytics YOLO đơn giản hóa việc sử dụng chúng cho các nhiệm vụ AI.

Model weights are the learnable parameters within a machine learning model that transform input data into predicted outputs. In a neural network, these weights represent the strength of the connections between neurons across different layers. When a model is initialized, these weights are usually set to random, small values, meaning the model "knows" nothing. Through a process called training, the model iteratively adjusts these weights based on errors it makes, gradually learning to recognize patterns, features, and relationships within the data. You can think of model weights as the "memory" or "knowledge" of the AI; they store what the system has learned from its training data.

The Role of Weights in Learning

The primary goal of training a neural network is to find the optimal set of model weights that minimizes the error between the model's predictions and the actual ground truth. This process involves passing data through the network—a step known as the forward pass—and then calculating a loss value using a specific loss function. If the prediction is incorrect, an optimization algorithm like Stochastic Gradient Descent (SGD) or the newer Muon optimizer used in YOLO26 calculates how much each weight contributed to the error.

Through a technique called backpropagation, the algorithm updates the weights slightly to reduce the error for the next time. This cycle repeats thousands or millions of times until the model weights stabilize and the system achieves high accuracy. Once training is complete, the weights are "frozen" and saved, allowing the model to be deployed for inference on new, unseen data.

Model Weights vs. Biases

It is important to distinguish between weights and biases, as they work together but serve different purposes. While model weights determine the strength and direction of the connection between neurons (controlling the slope of the activation), biases allow the activation function to be shifted to the left or right. This offset ensures that the model can fit the data better, even when all input features are zero. Together, weights and biases form the learnable parameters that define the behavior of architectures like Convolutional Neural Networks (CNNs).

Các Ứng dụng Thực tế

Model weights are the core component that enables AI systems to function across various industries. Here are two concrete examples of how they are applied:

  • Computer Vision in Retail: In a smart supermarket system, a model like YOLO26 uses its trained weights to identify products on a shelf. The weights have "learned" visual features—such as the shape of a cereal box or the color of a soda can—allowing the system to detect items, manage inventory, and even facilitate automated checkout processes efficiently.
  • Medical Image Analysis: In healthcare, deep learning models utilize specialized weights to analyze X-rays or MRI scans. For instance, a model trained for tumor detection uses its weights to distinguish between healthy tissue and potential anomalies. These weights capture complex, non-linear patterns in pixel data that might be subtle to the human eye, assisting radiologists in making faster diagnoses.

Saving and Loading Weights

In practice, working with model weights involves saving the trained parameters to a file and loading them later for prediction or tinh chỉnh. In the Ultralytics ecosystem, these are typically stored as .pt (PyTorch) files.

Here is a simple example of how to load pre-trained weights into a YOLO model and run a prediction:

from ultralytics import YOLO

# Load a model with pre-trained weights (e.g., YOLO26n)
model = YOLO("yolo26n.pt")

# Run inference on an image using the loaded weights
results = model("https://ultralytics.com/images/bus.jpg")

# Print the number of detected objects
print(f"Detected {len(results[0].boxes)} objects.")

Transfer Learning and Fine-Tuning

One of the most powerful aspects of model weights is their portability. Instead of training a model from scratch—which requires massive datasets and significant compute power—developers often use transfer learning. This involves taking a model with weights pre-trained on a large dataset like COCO or ImageNet and adapting it to a specific task.

For example, you might take the weights from a general object detector and fine-tune them on a smaller dataset of solar panels. Because the pre-trained weights already understand edges, shapes, and textures, the model converges much faster and requires less labeled data. Tools like the Ultralytics Platform simplify this process, allowing teams to manage datasets, train models on the cloud, and deploy optimized weights to edge devices seamlessly.

Compression and Optimization

Modern AI research often focuses on reducing the file size of model weights without sacrificing performance, a process known as model quantization. By reducing the precision of the weights (e.g., from 32-bit floating-point to 8-bit integers), developers can significantly decrease memory usage and improve inference speed. This is crucial for deploying models on resource-constrained hardware like mobile phones or Raspberry Pi devices. Additionally, techniques like pruning remove weights that contribute little to the output, further streamlining the model for real-time applications.

Tham gia Ultralytics cộng đồng

Tham gia vào tương lai của AI. Kết nối, hợp tác và phát triển cùng với những nhà đổi mới toàn cầu

Tham gia ngay