Tinh chỉnh các mô hình học máy như Ultralytics YOLO cho các nhiệm vụ cụ thể. Tìm hiểu các phương pháp, ứng dụng và thực hành tốt nhất tại đây!
Fine-tuning is a fundamental process in machine learning (ML) that involves adapting a pre-trained model to a specific task or dataset. Instead of training from scratch—which requires massive amounts of data, time, and computational power—developers start with a "foundation model" that has already learned general features from a vast dataset like ImageNet. This approach is a practical implementation of transfer learning, allowing AI systems to achieve high performance on niche problems with significantly fewer resources.
The core idea behind fine-tuning is to leverage the "knowledge" a model has already acquired. A base model typically possesses a robust understanding of fundamental visual elements, such as edges, textures, and shapes. During the fine-tuning process, the model's parameters (weights) are adjusted slightly to accommodate the nuances of new, specialized data.
This adjustment is usually achieved through gradient descent using a lower learning rate. A conservative learning rate ensures that the valuable features learned during the initial pre-training are refined rather than destroyed. In many computer vision (CV) workflows, engineers may freeze the initial layers of the backbone—which detect universal features—and only update the deeper layers and the detection head responsible for making final class predictions.
Fine-tuning bridges the gap between general AI capabilities and specific industry requirements. It allows generic models to become specialized experts.
It is helpful to distinguish fine-tuning from full training to understand when to use each approach.
Modern frameworks make this process accessible. For instance, the Ultralytics Platform simplifies the workflow by handling dataset management and cloud training automatically. However, developers can also fine-tune models locally using Python.
The following example demonstrates how to fine-tune a pre-trained
YOLO26 model on a custom dataset. Notice that we load
yolo26n.pt (the pre-trained weights) rather than a simplified configuration file, which signals the
library to initiate transfer learning.
from ultralytics import YOLO
# Load a pre-trained YOLO26 model (n=nano size)
# This automatically loads weights trained on COCO
model = YOLO("yolo26n.pt")
# Fine-tune the model on a custom dataset (e.g., 'coco8.yaml')
# The 'epochs' argument determines how many passes over the data occur
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)
# The model is now fine-tuned and ready for specific inference tasks
To achieve the best results, the quality of the new dataset is paramount. Using tools for data augmentation can artificially expand a small dataset by rotating, flipping, or adjusting the brightness of images, preventing overfitting. Additionally, monitoring metrics like validation loss and mean Average Precision (mAP) ensures the model generalizes well to unseen data.
For those managing complex workflows, employing MLOps strategies and tools like experiment tracking can help maintain version control over different fine-tuned iterations. Whether for object detection or instance segmentation, fine-tuning remains the industry standard for deploying effective AI solutions.