ultralytics
It is a Python library focusing on computer vision tasks, especiallyYOLO(You Only Look Once)The series of models are the core and provide a simple and easy-to-use interface, supporting tasks such as object detection, instance segmentation, and pose estimation. This article will introduce in detailultralytics
Library functions, installation methods, core modules and usage examples.
1. Introduction to ultralytics library
ultralytics
The library was developed by the Ultralytics team and aims to provide efficient, flexible and easy-to-use tools for the YOLO family of models. It supports the latest versions of YOLO models such as YOLOv5, YOLOv8, etc., and provides the following core functions:
- Target detection: Detect targets in images or videos.
- Instance segmentation: Perform pixel-level segmentation of the target.
- Posture estimation: The key points of the target (such as human posture).
- Model training: Supports training of custom datasets.
- Model Export: Export the model to multiple formats (such as ONNX, TensorRT, etc.).
2. Install ultralytics
ultralytics
It can be installed through pip:
pip install ultralytics
After the installation is completed, you can verify that the installation is successful through the following command:
import ultralytics print(ultralytics.__version__)
3. Core modules and functions
(1) YOLO model loading and reasoning
ultralytics
ProvidedYOLO
Class, used to load pretrained models or custom models and perform inference.
Loading the model
from ultralytics import YOLO # Load the pretrained modelmodel = YOLO("") # YOLOv8 Nano Model
reasoning
# Reasoning a single imageresults = model("") # Show results()
Save the results
# Save the test results("")
(2) Model training
ultralytics
Supports training of custom datasets.
Prepare the dataset
The data set needs to be organized in YOLO format:
dataset/ ├── images/ │ ├── train/ │ └── val/ └── labels/ ├── train/ └── val/
Training the model
# Loading the modelmodel = YOLO("") # Train the modelresults = (data="", epochs=50, imgsz=640)
(3) Model verification
After training is completed, the model performance can be evaluated using the validation set.
# Verify the modelmetrics = () print() # Print mAP value
(4) Model Export
ultralytics
Supports exporting models to multiple formats for deployment on other platforms.
# Export to ONNX format(format="onnx")
4. Use examples
Target detection
from ultralytics import YOLO # Loading the modelmodel = YOLO("") # Reasoning imagesresults = model("") # Show results()
Instance segmentation
from ultralytics import YOLO # Load the instance segmentation modelmodel = YOLO("") # Reasoning imagesresults = model("") # Show split results()
Posture estimation
from ultralytics import YOLO # Loading the pose estimation modelmodel = YOLO("") # Reasoning imagesresults = model("") # Show pose estimation results()
Video reasoning
from ultralytics import YOLO # Loading the modelmodel = YOLO("") # Reasoning videosresults = model("video.mp4") # Save the results("output.mp4")
5. Advanced features
(1) Custom model
ultralytics
Supports loading of customized training models.
from ultralytics import YOLO # Load custom modelmodel = YOLO("custom_model.pt") # Reasoningresults = model("")
(2) Multiple GPU training
ultralytics
Supports multi-GPU training to speed up the training process.
# Train with 4 GPUsresults = (data="", epochs=50, imgsz=640, device=[0, 1, 2, 3])
(3) TensorRT acceleration
ultralytics
Supports exporting models to TensorRT format to accelerate inference on NVIDIA GPUs.
# Export to TensorRT format(format="engine")
6. Summary
ultralytics
It is a powerful and easy-to-use computer vision library, especially suitable for the applications of the YOLO series of models. It provides complete functions from model loading, inference, training to export, and supports a variety of tasks such as object detection, instance segmentation, and pose estimation. Whether it is research or production environment,ultralytics
All can meet your needs.
Hope this article helps you get started quicklyultralytics
Library! If you have any questions, please leave a message in the comment area to discuss! 😊
Reference link
Ultralytics official documentation
YOLOv8 GitHub repository
This is the end of this article about the detailed explanation of Python's ultralytics library. For more related contents of Python ultralytics library, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!